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.

Be the first one to answer
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at ION Group

Q. Explain the time complexity of a binary tree.
Q. What are the four pillars of OOP?
Q. Implement a stack using a linked list.
Software Developer 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