š PracticeEasyAlgorithm ProblemCoding Ready
Climbing Stairs
dynamic-programmingmathmemoization
LeetCode #70
Updated Dec 20, 2025
Question
You are climbing a staircase. It takes n steps to reach the top.
LeetCode: Climbing Stairs
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Example:
Input: n = 2
Output: 2
Explanation:
1. 1 step + 1 step
2. 2 steps
Input: n = 3
Output: 3
Explanation:
1. 1 step + 1 step + 1 step
2. 1 step + 2 steps
3. 2 steps + 1 step
Hints
Hint 1
Think about the pattern: how many ways to reach step n if you can come from step n-1 or step n-2?
Hint 2
This is actually the Fibonacci sequence! ways(n) = ways(n-1) + ways(n-2)
Hint 3
You only need to keep track of the last two values, not the entire array. Can you optimize space to O(1)?
Your Solution
python
Auto-saves every 30s
Try solving the problem first before viewing the solution
Learning Resources
0:00time spent