Step count problem | Find the number of possible combinations to reach the final step
You are trying to climb on a staircase. There are N number of steps. You can only climb one or two steps at one time. Now you have to find out the number of possible combinations to reach the final step.
Input:
First-line contains T Testcases,
T no. of lines along with the step count(N).
E.g.
3
4
5
6
Output:
Print the number of possible valid steps
to reach the last step.
Example
T = 3
Input:
4
Output:
5
Input:
5
Output:
8
Input:
6
Output:
13
To find out the possible combination to reach the last step is a problem of combination. We are using the Dynamic programming approach to solve it with less time complexity.
To solve this problem, we will follow these steps,
Let f(i)= no. Of possible combination to reach the ith step. f(i)= f(i-1) +f(i-2)
C++ Implementation:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer