Climbing Stairs
Easy Dynamic Programming
n is the number of steps in a staircase. You start at the bottom, and each move takes you up either one step or two steps.
Two climbs are different if their moves, taken in order, are different: one step then two is not the same climb as two steps then one.
Return the number of different ways to climb to the top, landing exactly on step n.
Example 1
Input: n = 4
Output: 5
The five climbs are 1 + 1 + 1 + 1, 1 + 1 + 2, 1 + 2 + 1, 2 + 1 + 1 and 2 + 2.
Example 2
Input: n = 1
Output: 1
Example 3
Input: n = 6
Output: 13
Constraints
1 ≤ n ≤ 45- The answer is at most 1,836,311,903 (for
n = 45), so it fits in a 32-bit signed integer; forn = 46it would not
Solve it here
Write it in Python, Java or C++, run it on your own cases, and submit against hidden tests.
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
See the AI roundWatch the explanation
More Dynamic Programming
- Maximum SubarrayAI round · Medium
- Best Time to Buy and Sell StockAI round · Easy
- Longest Increasing SubsequenceAI round · Medium
- Coin ChangeAI round · Medium
- Unique PathsAI round · Medium