Loading problem…
You're building a feature that calculates the number of ways to reach a destination. This is a classic dynamic programming problem that appears in many variations.
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?
climbStairs(2); // 2
// Ways: 1 step + 1 step, or 2 steps
climbStairs(3); // 3
// Ways: 1+1+1, 1+2, 2+1
climbStairs(4); // 5
// Ways: 1+1+1+1, 1+1+2, 1+2+1, 2+1+1, 2+2This problem models real scenarios: