# Jump Game II

## Prim's algorithm

This solution looks like Prim's algorithm.

- jump to the furthest reachable point
- update
`maxjump`

like Jump Game `count = count + 1`

- loop until reach the end

### Source code *Read on Github*

```
1 public class Solution {
2 public int jump(int[] A) {
3 int count = 0;
4 int laststep = 0;
5
6 for(int i = 0; i < A.length - 1; /**/){
7
8 int maxstep = i + A[i];
9 for(int j = laststep + 1; j <= i; j++){
10 maxstep = Math.max(maxstep, j + A[j]);
11 }
12
13 laststep = i;
14 i = maxstep;
15
16 count++;
17 }
18
19 return count;
20 }
21 }
```