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.
The task is to find the number of distinct ways to move from the 0th to the Nth stair by ascending one or two steps at a time.
Use dynamic programming to solve this problem efficiently.
The number of wa...read more
Top NCR Voyix Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Reviews
Interviews
Salaries
Users/Month