
Asked in NCR Corporation
Count Distinct Ways to Reach the Nth Stairs
Consider a scenario where you have been given a number of stairs. You start at the 0th stair and need to reach the Nth stair. With each stride, you can choose to either ascend one step or two steps. Your task is to determine the number of distinct ways to move from the 0th to the Nth stair.
Input:
N = 3
Output:
3
Example:
The example scenarios could be:
- Climbing one step at a time: (0, 1), (1, 2), (2, 3)
- Climbing first two steps then one step: (0, 2), (2, 3)
- Climbing one step then two steps: (0, 1), (1, 3)
Constraints:
- 1 <= T <= 100
- 0 <= N <= 1018
Note:
You do not need to print anything; input and output handling are already managed. Simply implement the required logic in the function.
Sharan. Medamoni
5mo
public class Staircase { // Function to count the number of ways to reach the nth stair public static int countWays(int n) { if (n <= 1) { return 1; } // Array to store the number of ways to reach ...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at NCR Corporation
Q. Longest Palindromic Substring Problem Statement You are provided with a string S...read more
Q. Can you describe your projects and the tech stack you used in them?
Q. Find the Third Greatest Element Given an array 'ARR' of 'N' distinct integers, d...read more
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for NCR Corporation Software Developer Intern
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

