‹ DS&A interview · Socratic
DSA · Dynamic Programming · #49

Climbing Stairs

Module 47 · difficulty 2/5·30:00starts on first keystroke

You are climbing a staircase with `n` steps. Each time you can climb either **1** or **2** steps. Return the number of **distinct ways** you can climb to the top. Implement `climbStairs(n)` which takes a non-negative integer `n` and returns the count of distinct ways as a number.

Examples
  • n = 2 2Two ways: (1+1) and (2).
  • n = 3 3Three ways: (1+1+1), (1+2), (2+1).
  • n = 5 8Follows the Fibonacci sequence.
Constraints
  • · 0 <= n <= 45
  • · There is at least one way to climb 0 steps (the empty climb), so climbStairs(0) === 1.
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.