Count Ways To Reach The N-th Stair Problem Statement
You are given a number of stairs, N
. Starting at the 0th stair, you need to reach the Nth stair. Each time you can either climb one step or two steps. You have to return the number of distinct ways to climb from the 0th step to the Nth step.
Input:
The first line contains an integer 'T', representing the number of test cases. For each test case, there is a single integer 'N' denoting the number of stairs.
Output:
For each test case, print the number of distinct ways to climb to the top of the stairs. Since the result could be large, return it modulo 10^9+7. Output for each test case should be printed in a separate line.
Example:
Input:
N=3
Output:
3
Explanation:
There are three ways to climb to the third stair: (0, 1, 2, 3) by taking one step at a time, (0, 2, 3) by taking a two-step followed by a one-step, and (0, 1, 3) by taking a one-step followed by a two-step.
Constraints:
1 ≤ T ≤ 100
0 ≤ N ≤ 1018
Note:
You do not need to print anything. This has already been managed.

AnswerBot
4mo
The problem involves finding the number of distinct ways to climb to the Nth stair by taking one or two steps at a time.
Use dynamic programming to solve this problem efficiently.
The number of ways to ...read more
Help your peers!
Add answer anonymously...
Nagarro Associate Engineer interview questions & answers
An Associate Engineer was asked 10mo agoQ. Write a program.
An Associate Engineer was asked 10mo agoQ. How do you find the largest element in an array with O(N) complexity?
An Associate Engineer was asked 10mo agoQ. How do you detect a loop in a linked list?
Popular interview questions of Associate Engineer
An Associate Engineer was asked 10mo agoQ1. Write a program.
An Associate Engineer was asked 10mo agoQ2. How do you find the largest element in an array with O(N) complexity?
An Associate Engineer was asked 10mo agoQ3. How do you detect a loop in a linked list?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

