Count Ways to Reach the N-th Stair Problem Statement

You are provided with a number of stairs, and initially, you are located at the 0th stair. You need to reach the Nth stair, and you can climb one or two steps at a time. Your task is to determine the number of distinct ways to climb from the 0th to the Nth stair.

Input:

The first line contains an integer 'T', denoting the number of test cases. For each test case, there is a single integer 'N' which represents the number of stairs.

Output:

For each test case, print the number of distinct ways to reach the Nth stair, modulo 10^9+7. The result for each test case should be on a new line.

Example:

Input:
N=3
Output:
The number of distinct ways to reach the 3rd stair is 3, considering all possible sequences of climbing as shown in the example.

Constraints:

  • 1 <= T <= 100
  • 0 <= N <= 10^18

Note:

You are not required to print anything yourself; the output handling is managed by the system.

AnswerBot
4mo

The problem involves counting the number of distinct ways to climb N stairs by taking 1 or 2 steps at a time.

  • Use dynamic programming to solve this problem efficiently.

  • The number of ways to reach the N...read more

empoweringsugar
3mo
DP(n) = DP(n-1) + DP(n-2_
Help your peers!
Select
Add answer anonymously...

Freshworks Senior Software Engineer interview questions & answers

A Senior Software Engineer was asked 8mo agoQ. Implement a debounce function.
A Senior Software Engineer was asked Q. Given a Binary Search Tree (BST), find the kth largest element.
A Senior Software Engineer was asked Q. Given an array of integers, find the number of pairs whose sum is a perfect squa...read more

Popular interview questions of Senior Software Engineer

A Senior Software Engineer was asked Q1. Given a Binary Search Tree (BST), find the kth largest element.
A Senior Software Engineer was asked Q2. Given an array of integers, find the number of pairs whose sum is a perfect squa...read more
A Senior Software Engineer was asked Q3. Given an array, for each element, find the immediate higher element to its right...read more
Freshworks Senior Software 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