Challenge: Climbing Stairs
Completed
You can climb 1 or 2 steps at a time. Print the number of different ways to climb n steps, using a DP table or two variables.
Input
One whole number n (1 ≤ n ≤ 90).
Output
The number of ways.
Example
Input
2
Output
2
Editor
Python
Hints
ways[i] = ways[i - 1] + ways[i - 2].
ways[0] = ways[1] = 1.
Solution explanation
The same pattern as Fibonacci, solved bottom-up in O(n).
Show solution
n = int(input())
a, b = 1, 1
for _ in range(n - 1):
a, b = b, a + b
print(b) Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module