Problem · Dynamic Programming

Count Staircase Ways

Learn this problem
EasyGoldman Sachs logoGoldman SachsFULLTIMEPHONE SCREEN

Problem 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) → long

Examples

Example 1

n = 4return = 5

The valid step sequences are 1111, 112, 121, 211, and 22.

Example 2

n = 0return = 1

The empty climb is one valid way.

Constraints

  • 0 <= n <= 90
  • The answer fits in a signed 64-bit integer.

More Goldman Sachs problems

drafts saved locally
public long countStaircaseWays(int n) {
  // write your code here
}
n4
expected5
checking account