Back to Practice Dashboard
Top 150 InterviewMedium
Climbing Stairs
Learn how to solve the 'Climbing Stairs' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
Medium
You are climbing a staircase. It takes n steps to reach the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Constraints
- •1 <= n <= 45
Examples
Example 1
Input
n = 2
Output
2
Explanation
There are two ways to climb to the top: 1. 1 step + 1 step, 2. 2 steps.
Example 2
Input
n = 3
Output
3
Explanation
There are three ways to climb to the top: 1. 1 step + 1 step + 1 step, 2. 1 step + 2 steps, 3. 2 steps + 1 step.
Need a Hint?
Define subproblem states, establish the recurrence relation, and use memoization (top-down) or tabulation (bottom-up).
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.