public class Solution {

public int jump(int[] nums) {

```
int maxJump = nums[0];
int lastmax = nums[0];
int maxi = 0;
int maxIndex = nums.length-1;
if(maxIndex==0)return 0;
int count = 0;
for(int i = 0;i<=lastmax;i++){
if(i+nums[i]>maxJump){
maxJump = i+nums[i];
maxi = i;
}
if(i==lastmax){
if(lastmax!=maxJump)count++;
i = maxi;
lastmax= maxJump;
maxJump = lastmax;
}
if(lastmax>=maxIndex)return ++count;
}
return -1;
}
```

}