Loading...
Loading...
Loading...
A staircase has n steps. A person climbs one or two steps at a time. Print the number of different ways to reach the top.
Example 1
Input
4
Output
5
The ways are 1111, 112, 121, 211 and 22.
Example 2
Input
1
Output
1
Try the problem first. Open one hint at a time.
The last move was one step from n - 1 or two steps from n - 2.
Keep only the last two counts in two variables.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor