Dynamic programming
Count ordered ways to climb exactly n stairs, using one- or two-stair moves.
Examples
Example 1
Input
n = 0
Expected output
1
Example 2
Input
n = 3
Expected output
3
Example 3
Input
n = 4
Expected output
5
Hints and solution
Hint 1
Write the counts for zero and one before considering the final hop.
Hint 2
For each new count, add the two previous counts.
Reveal worked answer
The table begins 1, 1, 2, 3, 5. A hop sequence finishing at stair 4 either comes from stair 3 or stair 2, giving 3 + 2 = 5 arrangements.