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!
Select
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?
Associate Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits