Climbing Stairs
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write climbStairs(n): a staircase has n steps, and you climb it 1 or 2 steps at a time. Return how many different sequences of steps take you to the top. n is a whole number from 1 to 75, so the answer stays below 2 to the power 53 and fits exactly in a JavaScript number. For example, climbStairs(3) is 3: 1 + 1 + 1, 1 + 2 and 2 + 1. The checks go up to 75 steps, so trying every sequence one by one is too slow: build the count up from the bottom step.
Your code must pass
- Counts the ways up a few steps
- Handles one and two steps
- Is fast enough for 75 steps