Skip to interview prep
Apexed

9. Climbing Stairs

EasyDynamic programming

You can climb 1 or 2 steps at a time. Return the number of distinct ways to reach the top of a staircase with n steps.

Example 1

Input: n = 2
Output: 2
Explanation: 1+1 or 2

Example 2

Input: n = 3
Output: 3
Explanation: 1+1+1, 1+2, 2+1

Constraints

  • 1 ≤ n ≤ 45

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 6 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Climbing Stairs — coding interview practice — Apexed