
Asked in Nagarro
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...
Top Associate Engineer Interview Questions Asked at Nagarro
Q. Write a program.
Q. How do you find the largest element in an array with O(N) complexity?
Q. How do you detect a loop in a linked list?
Interview Questions Asked to Associate Engineer at Other Companies
Top Skill-Based Questions for Nagarro Associate Engineer
Python Interview Questions and Answers
400 Questions
Data Structures Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Networking Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
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

