Menu
CoddyTech

Climbing Stairs

You stand at the bottom of a staircase with n steps. Every move climbs either 1 step or 2 steps. Two climbs count as different when their sequences of moves differ, so 1, 2 and 2, 1 are two ways. Your function gets n and returns the number of distinct ways to reach the top.

Function

climbStairs(n: integer) → integer
ninteger
the number of steps in the staircase
Returnsinteger
the number of distinct sequences of 1-steps and 2-steps that reach step n

Constraints

  • 1 ≤ n ≤ 45
  • The answer fits in a signed 32-bit integer: n = 45 gives 1836311903.

Examples

Input
n = 3
Output
3
Explanation
Three steps can be climbed as 1, 1, 1, as 1, 2 or as 2, 1, so there are 3 ways.

lock icon+13 hidden tests on Submit

challenge icon

Follow-up

What if some steps are broken and you may never stand on them? How does the recurrence change, and what is the count for a broken step?

Reset code
def climbStairs(n):
    # Write code here
Test cases

Case 1

Case 2

Input

n = 3

Expected

3