Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Ascending Vein

Learn
Play
Prove
Problem context and objectives
Mission briefing

Energy-route planner · A runner crosses a line of power stations

Build each decision from smaller outcomes already solved: The Ascending Vein.

Re-solving the same future branches drains exponential energy.

How you win

  1. 1Recognize when Longest increasing subsequence matches the clues
  2. 2Keep this true after every move: dp[i] is the longest strictly increasing subsequence ending exactly at i
  3. 3Reach the result within O(n squared) time and O(n) space

Rules and pressure

  • Target cost: O(n squared) time and O(n) space
  • State rule: dp[i] is the longest strictly increasing subsequence ending exactly at i
Lesson 1 of 3

Live algorithm trace

Longest increasing subsequence

Complete execution
1 of 5

Initialize every possible ending as a one-value subsequence.

1dp[i] starts at 1
2for each ending index i
3scan earlier index j
4if nums[j] < nums[i]
5dp[i] = max(dp[i], dp[j] + 1)
6return max(dp)
dp = all ones
Truth to preserve / Cost target
Truth to preserve

dp[i] is the longest strictly increasing subsequence ending exactly at i

Cost target

O(n squared) time and O(n) space

For every index, find the longest increasing subsequence ending there by extending an earlier smaller value. The global answer may end anywhere.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead