ORIGINAL CODING QUESTION
Staircase with three stride lengths
A fitness challenge on the office staircase lets you climb 1, 2 or 3 steps per move. Count the distinct ordered move sequences that finish exactly on step n, modulo 1,000,000,007. For n = 0 the empty sequence counts once.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
One integer n.
Constraints
0 ≤ n ≤ 200.
Example 1
Input
4
Output
7
There are seven sequences, such as 1+3, 3+1, 2+2 and 1+1+1+1.
Example 2
Input
0
Output
1
Standing still is the single way to finish at step 0.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
The last move was 1, 2 or 3 steps long.
Hint 2
ways(n) = ways(n-1) + ways(n-2) + ways(n-3), with ways(0) = 1.
Hint 3
Keep only the last three values and reduce modulo 1,000,000,007 each time.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →