Count Ways to Climb Stairs Problem
Given a staircase with a certain number of steps, you start at the 0th step, and your goal is to reach the Nth step. At every step, you have the option to move either one step or two steps up the stairs. Your task is to determine the number of distinct ways to reach the Nth step from the 0th step.
Input:
The input consists of multiple test cases.
The first line of the input:
T
represents the number of test cases.
For each test case:
N
represents the number of stairs.
Output:
For each test case, output the number of distinct ways to reach the top of the stairs. Since the result can be very large, return the result modulo 10^9+7.
Example:
Input:
3
2
3
4
Output:
2
3
5
Explanation:
For N=3: You can reach the 3rd step by {(0,1,2,3)}, {(0,2,3)}, or {(0,1,3)}. So, there are 3 distinct ways to climb.
Constraints:
1 ≤ T ≤ 100
0 ≤ N ≤ 1018
Note:
You are not required to print anything; it has already been handled. Just implement the function and return the answer.
Count the number of distinct ways to climb stairs by moving either one step or two steps at a time.
Use dynamic programming to solve the problem efficiently.
Keep track of the number of ways to reach ea...read more
Top Sourcefuse Technologies Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Reviews
Interviews
Salaries
Users/Month