Minimum number of jumps | Practice | GeeksforGeeks

int minJumps(int arr[], int n){
// Your code here
int count=1;
count+=arr[0];
int i=1;
while(count<=n-1)
{
    count+=arr[count-1];
    if(arr[count-1]==0&&count!=n-1)
    {
        return -1;
    }
    i++;
}
return i;

}
This submission of mine gives TLE according to me this is a O(n) solution.
Pls help me out to solve this problem

Try this case:
1
10
5 9 1 2 3 1 5 6 7 8
Your code’s output will be: 3
Right output is : 2

1 Like

1
10
2 3 1 1 2 4 2 0 1 1
can you please tell me about the jumps coz the answer is 4 and what i am getting is 6 in thw test case given above on dry running the code as well as on compiling.

got it i got the question wrong