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
Take a moment to understand the problem and think of your approach before you start coding.