Climbing Stairs - Problem
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?
Note: Given n will be a positive integer.
Input & Output
Example 1 — Small Staircase
$
Input:
n = 2
›
Output:
2
💡 Note:
There are two ways to climb to the top: 1. 1 step + 1 step, 2. 2 steps
Example 2 — Medium Staircase
$
Input:
n = 3
›
Output:
3
💡 Note:
There are three ways: 1. 1+1+1 steps, 2. 1+2 steps, 3. 2+1 steps
Example 3 — Single Step
$
Input:
n = 1
›
Output:
1
💡 Note:
Only one way to climb 1 step: take 1 step
Constraints
- 1 ≤ n ≤ 45
Visualization
Tap to expand
Understanding the Visualization
1
Input
Number of steps n to reach the top
2
Process
Count all possible combinations of 1-step and 2-step moves
3
Output
Total number of distinct ways
Key Takeaway
🎯 Key Insight: This is the Fibonacci sequence in disguise - each step count equals the sum of the previous two step counts
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code