AlgoScope

Climbing Stairs

Algorithmbeginner1D Dynamic Programming

Ways to reach step n = ways(n-1) + ways(n-2).

Decision · step 2 of 9DP in One Row: Ways to climb 8 stairs
101122345678i

dp[2] = dp[1] + dp[0] = 1 + 1 = 2.

Open in the player →or start at step 2

What you will see

Same shape as Fibonacci; each step's count is the sum of the two before it.

How dp in one row works →

Cost

BestO(n)
AverageO(n)
WorstO(n)
SpaceO(1)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.

Screen readers: Table cells announce their state and value; each step announces which cells were read and the value written.

Reduced motion: Dependency arrows appear statically and the cell value crossfades.

Before this

Leads to

Topics that need this one first.

Taught by the same lesson

DP in One Row covers these too, in the same run.