Array ( [0] => [1] => questions [2] => Basic [3] => Common-Steps )
A child is running up a staircase with n steps and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs.
A single integer n denoting number of steps.
Total no. of ways child can run up.
4
7
3
4
10
274
Login to see Discussion
This was a recursion problem. But recursion took time, so dynamic programming can be applied using the steps named list. No. of steps for a number n can be determined by n-1, n-2, n-3. All the results were calculated by the formula and stored for later use. So that again and again already calculated values need not be calculated again.
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution