Blind 75
49 / 75Free practice

Climbing Stairs

Easy · Dynamic programming

Jump to code

A staircase has n ≥ 1 steps. You can climb one or two steps at a time. Count the different ordered sequences of moves that reach the top exactly.

Examples

Example 1

n = 2

Output: 2

Example 2

n = 3

Output: 3

Constraints

  • 1 <= n <= 30
Need a hint?

The final move comes from one or two steps below.

Real dynamic programming interview questions

Questions on the same topic that candidates reported from real company interviews. Some company questions are locked and open with Premium or XP.

Browse all real coding interview questions

Accepted submissions mark this problem complete. Progress stays in this browser.

Run checks 5 examples. Submit checks all 7 cases. A free account runs this problem; no XP needed.
Language
Case 1
Input
[
  2
]
Expected
2
Case 2
Input
[
  3
]
Expected
3
Case 3
Input
[
  1
]
Expected
1
Case 4
Input
[
  4
]
Expected
5
Case 5
Input
[
  5
]
Expected
8

Drafts are saved per language in this browser when storage is available.