โ† Trees, Graphs & DP
#8 most askedVery commonEasy1D DP

Climbing Stairs

New to 1D DP? Learn it from scratch first
Dynamic Programming, Demystified โ†’
๐Ÿข Asked in real interviews
No reports yet. Were you asked this? Be the first to say where.
I was asked this

You can climb 1 or 2 steps at a time. How many different ways are there to climb n steps?

climb_stairs(3) โ†’ 3 (1+1+1, 1+2, 2+1).

๐Ÿงช Practice

Write your solution, then press Run tests. Explain your approach out loud as you go.

Python
def climb_stairs(n):
    pass

Output appears here. Press Run or Ctrl/โŒ˜ + Enter.

Try it first. Struggling for a few minutes is how it sticks.