Idea:

start from the next node where last step ends to the node where the last step can reach, remember the farthest index this step can reach. Go until there is no way to go or reach the end

Example: 2, 3,1,2,1,4

The first step can reach A[2] becase A[0] is 2, next loop go through from A[1] to A[2], for A[1] it can go to 1 (node index)+3(node value) =4, for A[2], it go reach 2 (node index)+1(node value) = 3, the max inde step 2 can reach is 4 then. The next step goes from A[3] to A[4], get where it can reach for next step, it's 6. It reach the end, we know the min steps. For the case, it can't reach end, the max step it can go small than the start, terminate and return 0.

Since it goes through the array only once, it's O(n), O(1) solution

```
class Solution {
public:
int jump(int A[], int n) {
if(n<=1) return 0;
int i =1;
int minstep = 1;
int maxDis = A[0]; //the max index the next step can go
while((maxDis+1)>i && (maxDis< (n-1))) // when maxDis + 1 <=i, it means it can't go further, return 0
{
int j = maxDis+1;
for(;i<j;i++) // caculate the max distance the next step can go
maxDis = max(A[i] + i, maxDis);
minstep++;
}
return (maxDis>=n-1)?minstep:0;
}
};
```