Facebook PixelClimbing Stairs — Coding Practice
Climbing StairsEasy

Climbing Stairs

Easy 19.5k52% acceptance
Dynamic ProgrammingMath

You are climbing a staircase with n steps. Each move you can climb 1 or 2 steps. In how many distinct ways can you reach the top?

Example 1
Input: n = 2
Output: 2
1+1 or 2.
Example 2
Input: n = 3
Output: 3
1+1+1, 1+2, or 2+1.
Constraints
  • 1 ≤ n ≤ 45
Asked atAmazonAdobeApple
JavaScript
Loading editor…
Case 1
2
expected: 2
Case 2
3
expected: 3
Case 3
5
expected: 8
Case 4
1
expected: 1