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 Count

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 Count.

Re-solving the same future branches drains exponential energy.

How you win

  1. 1Recognize when Number of longest increasing subsequences matches the clues
  2. 2Keep this true after every move: length[i] and count[i] exactly summarize increasing subsequences ending 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: length[i] and count[i] exactly summarize increasing subsequences ending at i
Lesson 1 of 3

Live algorithm trace

Number of longest increasing subsequences

Complete execution
1 of 6

Seed one singleton subsequence at every ending.

1length and count start at 1
2for each ending i
3for each smaller predecessor j
4if candidate length is better: replace length and count
5if equal: add predecessor count
6sum counts at global maximum length
lengths = [1,1,1,1,1]counts = [1,1,1,1,1]
Truth to preserve / Cost target
Truth to preserve

length[i] and count[i] exactly summarize increasing subsequences ending at i

Cost target

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

Every ending stores both its best length and the number of ways to achieve that length. Better predecessors replace the count; equally good predecessors add their counts.

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