Skip to content
playdsa
Preferences

Make yourself comfortable.

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

Theme
Advanced settings

Stair Memories

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: Stair Memories.

Re-solving the same future branches drains exponential energy.

How you win

  1. 1Recognize when One-dimensional dynamic programming matches the clues
  2. 2Keep this true after every move: previous states hold the exact number of ways to reach their stairs
  3. 3Reach the result within O(n)

Rules and pressure

  • Target cost: O(n)
  • State rule: previous states hold the exact number of ways to reach their stairs
Lesson 1 of 3

Live algorithm trace

One-dimensional dynamic programming

Complete execution
1 of 6

Base cases say there is one way to stand before climbing and one way to reach stair 1.

1one, two = 1, 1
2for each stair
3one, two = one + two, one
4return one
n = 5one = 1two = 1
Truth to preserve / Cost target
Truth to preserve

previous states hold the exact number of ways to reach their stairs

Cost target

O(n)

Dynamic programming names a state and reuses solved smaller states. To reach a stair, the last move came from one or two stairs below.

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