EasyDynamic Programming

Climbing Stairs

A staircase has n steps. Each move climbs 1 or 2 steps. Return the number of distinct ways to reach the top.

n = 2 → 2 (1+1, 2)n = 3 → 3 (1+1+1, 1+2, 2+1)

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Variables

The data structures the code is building

Staircase

The number on each step is filled in as it is computed

Time and space complexity

n = number of steps. The highlighted row is the solution being traced.

Keyboard: ← → step, Space play or pause. n from 1 to 45; drawings are capped at n = 6 for plain recursion, 12 for top-down and 20 for the loops.