Climb Stairs with One, Two, or Three Steps
Updated
Problem 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.
More Agoda interview questions
- Sort Ones, Twos, and Threes In PlacePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Molecular Weight of a Grouped FormulaONSITE INTERVIEW · Seen Oct 2026
- Minimum Daily Printing LimitONSITE INTERVIEW · Seen Aug 2026
- Rank Transform an ArrayONSITE INTERVIEW · Seen Aug 2026
- Minimum Absolute Difference PairsONSITE INTERVIEW · Seen Jun 2026
- Feasibility of Printing Within Given DaysONSITE INTERVIEW · Seen May 2026
- 3SumONSITE INTERVIEW · Seen May 2026
- Can Place FlowersPHONE SCREEN · Seen Nov 2026
- Reverse Words in a StringPHONE SCREEN · Seen Nov 2026
- Disk Space Window AnalyzerPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Climbing StairsAmazon · ONSITE INTERVIEW
- Climbing StairsAMD · ONSITE INTERVIEWAMD interview questions
- Climbing StairsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- N-th Fibonacci NumberBank of America · ONSITE INTERVIEWBank of America interview questions
- Fibonacci with Input ValidationMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
- Integral of a Sine PowerJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Climbing StairsExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions
- The Nth Number in the Fibonacci SequenceCapital One · PHONE SCREEN · ONSITE INTERVIEWCapital One interview questions
- Allocate Mailboxes with Squared DistanceLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Dice-Walk Winning ProbabilityGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions