Problem · Dynamic Programming
Climb Stairs with One, Two, or Three Steps
Learn this problemProblem statement
A staircase has n steps. Starting before the first step, each move climbs exactly 1, 2, or 3 steps.
Return the exact number of ordered move sequences that land exactly on step n. For n = 0, return 1 for the empty sequence.
Function
countStairWays(n: int) → longExamples
Example 1
n = 4return = 7The seven sequences are 1+1+1+1, 1+1+2, 1+2+1, 2+1+1, 2+2, 1+3, and 3+1.
Example 2
n = 0return = 1There is one way to climb zero steps: take no moves.
Constraints
0 <= n <= 50- The exact answer fits in a signed
64-bit integer.