You are at the start of an array. (in 0). Every index will hold the value of maximum steps you take from that index (if the value is 0 then the person cannot move) in one jump. You have to reach the end of the array. Print the minimum number of steps required to reach the endpoint. If it is not possible to reach the end, print -1.
Sample Input:
10 (Number of elements of the array)
5 5 0 4 1 4 5 5 3 2 (Steps taken at each jump)
Sample Output:
2
Explanation:
The first element is 5. Using that, we can reach 5 steps. So, reach the 5th index, which is 4. From there, we can make 4 steps, which leads us to the end of the array.
start -> 5 -> 4 -> end
@@coding::1@@
Recommended Programs