Climbing Stairs
Calculate the number of distinct ways to climb a staircase of n steps taking 1 or 2 steps at a time using memoized recursion.
01The problem
You are climbing a staircase. It takes n steps to reach the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
| Input | Output | Why |
|---|---|---|
n = 2 | 2 | 1+1 or 2 steps |
n = 3 | 3 | 1+1+1, 1+2, or 2+1 steps |
n = 4 | 5 | 5 distinct step combinations |
Constraints: 1 <= n <= 45.
Loading the rest of the lesson…