Although, I will expect you to come up with the recursive approach yourself because we have already covered this. But still, I will explain briefly. As always we will break down the problem into Expectation, Faith and then derive the Expectation from our Faith.

Here the **expectation** will be that **countPath(0)** will return the count of all paths from the index 0 to n.

The **Faith** will be that **countPath(1), countPath(2)** will return the count of all paths from index 1 to n and from index 2 to n. Why two functions in Faith? Because the value at 0 is 2, so it can at max take 2 jumps. So it can either reach 1 or reach 2. Now, let's derive **Expectation from Faith**.

If we have:

**x** ways to go from **a** to **D**

**y**ways to go from **b** to **D**

**z** ways to go from **c** to **D**

Then for going from **S** to **D** we will have **x+y+z**approaches.

Hence **countPaths(0) = countPaths(1) + countPaths(2)**

But we have to be careful about the jumps. The jumps we take should not get out of the range. Keeping these in mind I would insist you write the code yourself. If you face any difficulty you can refer to the code below.