Climbing Stairs
Ways to reach step n = ways(n-1) + ways(n-2).
Decision · step 2 of 9DP in One Row: Ways to climb 8 stairs
dp[2] = dp[1] + dp[0] = 1 + 1 = 2.
What you will see
Same shape as Fibonacci; each step's count is the sum of the two before it.
Cost
| Best | O(n) |
|---|---|
| Average | O(n) |
| Worst | O(n) |
| Space | O(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
Taught by the same lesson
DP in One Row covers these too, in the same run.