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
Add answer anonymously...
ION Group Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter