(int[] arr)
| 1 | class Solution{ |
| 2 | static int minJumps(int[] arr){ |
| 3 | // your code here |
| 4 | if(arr.length==1) |
| 5 | return 0; |
| 6 | |
| 7 | if(arr[0]==0) |
| 8 | return -1; |
| 9 | |
| 10 | int jump=0,halt=0; |
| 11 | int maxDist=Integer.MIN_VALUE; |
| 12 | for(int i=0;i<arr.length-1;i++) |
| 13 | { |
| 14 | if(arr[i]+i>=maxDist) |
| 15 | maxDist=arr[i]+i; |
| 16 | |
| 17 | if(i==halt) |
| 18 | { |
| 19 | halt=maxDist; |
| 20 | jump++; |
| 21 | if(halt>=arr.length-1) |
| 22 | break; |
| 23 | } |
| 24 | } |
| 25 | return (halt>=arr.length-1)?jump:-1; |
| 26 | } |
| 27 | } |
nothing calls this directly
no outgoing calls
no test coverage detected