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.

AnswerBot
4mo

Count the number of distinct ways to climb stairs by moving either one step or two steps at a time.

  • Use dynamic programming to solve the problem efficiently.

  • Keep track of the number of ways to reach ea...read more

Help your peers!
Select
Add answer anonymously...

Sourcefuse Technologies Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Delete a Node from a Linked List You are provided with a linked list of integers...read more
A Software Developer Intern was asked Q. Merge Sort Linked List Problem Statement You are given a singly linked list of i...read more
A Software Developer Intern was asked Q. Palindrome Substrings Given a string STR, your objective is to determine the tot...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Delete a Node from a Linked List You are provided with a linked list of integers...read more
A Software Developer Intern was asked Q2. Merge Sort Linked List Problem Statement You are given a singly linked list of i...read more
A Software Developer Intern was asked Q3. Palindrome Substrings Given a string STR, your objective is to determine the tot...read more
Sourcefuse Technologies Software Developer Intern 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