Climbing Steps
Easy
Question
You are climbing a staircase that takes n steps to reach the top.
Each time you take a step, you can either climb one or two steps. How many distinct ways can you climb to the top?
Input: n = 2
Output: 2
There are two ways to climb to the top.
- 1 step + 1 step
- 2 steps
Input: n = 3
Output: 3
There are three ways to climb to the top.
- 1 step + 1 step + 1 step
- 1 step + 2 steps
- 2 steps + 1 steps
Clarify the problem
What are some questions you'd ask an interviewer?
Understand the problem
What should we use for our base case?
f(1) = 1, f(2) = 2
f(0) = 1, f(1) = 1
f(2) = 2, f(3) = 3
f(1) = 1
All test cases pass! 🎉
Time limit exceeded
InputExpected OutputActual Output
Standard OutputScroll down...
Login or signup to save your code.
Uh oh... looks like you don't yet have access.
Not sure what this unlocks? Check out a free pattern section.