Problem · Dynamic Programming
Count Staircase Ways
Learn this problemProblem statement
A staircase has n steps. Starting before the first step, each move climbs exactly one or two steps.
Return the number of distinct ordered move sequences that land exactly on step n. For n = 0, return 1 for the empty sequence.
Function
countStaircaseWays(n: int) → longExamples
Example 1
n = 4return = 5The valid step sequences are 1111, 112, 121, 211, and 22.
Example 2
n = 0return = 1The empty climb is one valid way.
Constraints
0 <= n <= 90- The answer fits in a signed 64-bit integer.