Top 150 InterviewMedium

Climbing Stairs

Detailed guide and Python implementation for the 'Climbing Stairs' problem.

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?

Write a function climbStairs(n: int) -> int.

Constraints
  • 1 <= n <= 45

Examples

Example 1
Input
n = 2
Output
2
Explanation

There are two ways to climb: 1+1 steps, or 2 steps.

Example 2
Input
n = 3
Output
3
Explanation

There are three ways: 1+1+1 steps, 1+2 steps, or 2+1 steps.

Need a Hint?
Consider using 1D DP-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.