You're climbing a staircase with n steps. Each time you can climb 1 or 2 steps. How many distinct ways can you reach the top?
Why Fibonacci? From step n, you could have gotten there from:
n-1 (taking 1 step) → there are f(n-1) ways to reach step n-1n-2 (taking 2 steps) → there are f(n-2) ways to reach step n-2f(n) = f(n-1) + f(n-2)This is a classic DP problem disguised as recursion. Use memoization or bottom-up iteration to avoid exponential time.
climb_stairs(2)
2
climb_stairs(3)
3
climb_stairs(5)
8
climb_stairs(10)
89