Climbing Stairs
Problem
A staircase has n steps. You start on the ground (step 0) and on each move you may go up either one step or two steps. Count the number of distinct move sequences that land you exactly on step n. Two sequences are different if the list of step sizes differs, so 1,2 and 2,1 are counted separately.
nis a positive integer no larger than 60.- Return the exact count as an integer; it fits comfortably in 64 bits for this range.
Examples
n = 4→5. The sequences are1+1+1+1,1+1+2,1+2+1,2+1+1, and2+2.n = 6→13. Every sequence either ends with a 1-step from step 5 (8 ways) or a 2-step from step 4 (5 ways).n = 1→1. Only a single 1-step reaches the top.
Hints
- Think about the very last move you make before arriving on step
n. Where must you have been standing? - If you knew how many ways there are to reach step
n-1and stepn-2, could you combine those numbers without recounting anything? - This is a one-dimensional DP whose recurrence is the Fibonacci relation; you only ever need the two most recent values.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.