educative.io

https://www.educative.io/courses/algorithms-coding-interviews-python/mEGzKkrBAKG

image
Hi, can you please explain why there are 1 way to reach 0 steps? If there has no steps, shouldn’t the method be none too?

And what if the child can only take 1 or 2 steps?

thanks


Type your question above this line.

Course: https://www.educative.io/collection/10370001/5550095527313408
Lesson: https://www.educative.io/collection/page/10370001/5550095527313408/5122140560949248

Hello @Yuchuan_Han

In the first query, the staircase problem refers to the number of ways in which we can achieve the task. So, to achieve the target of climbing 0 steps, we have exactly one way and that is not taking a step.

For your second question, if the child can only take 1 or 2 steps at a time, we will take a sum of the previous 2 values in the series. So basically, you will add the last m values in the series where m = maximum number of steps the child can take.

Got it ! Thank you very much!