You are climbing a staircase that has n steps. Each time you can climb either 1 or 2 steps. How many distinct ways can you reach the top?
For example, if n = 3, there are 3 ways: (1+1+1), (1+2), (2+1).
Explain your approach to solving this problem and state the time and space complexity.
How to approach it
- Hint 1
Think about how many ways you can reach step n if you already know how to reach earlier steps.
- Hint 2
The number of ways to reach step n depends on how many ways you can reach step n-1 and step n-2.
- Hint 3
This follows the Fibonacci pattern: f(n) = f(n-1) + f(n-2), with base cases f(1) = 1 and f(2) = 2.
Ready to answer it out loud?
Record your answer in 1:00 and Preptile scores it 1–10 with specifics — what landed, what you skipped, and what to say next time.
Practising needs an invite code. Join the waitlist and we’ll send you one.