FastPrepClimbing Stairs

Climbing Stairs

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

You are climbing a staircase with n steps.

On each move, you may climb either 1 step or 2 steps. Return the number of distinct sequences of moves that reach exactly the top.

Function

climbStairs(n: int) → int

Examples

Example 1

n = 2return = 2

The two valid sequences are 1 + 1 and 2.

Example 2

n = 5return = 8

Every sequence ends with a one-step move from step 4 or a two-step move from step 3, giving 5 + 3 = 8.

Example 3

n = 1return = 1

There is one way to climb one step.

Constraints

  • 1 <= n <= 45.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int climbStairs(int n) {
    // Write your code here.
}
n2
expected2
Checking account…