in Algorithms edited by
853 views
2 votes
2 votes
You are given an array of elements where each array element represents the MAXIMUM number of jumps that can be made in the forward direction from that element. Now, consider the following array: {1, 3, 5, 8, 9, 2, 6, 7, 6).

What is the minimum number of jumps required to reach the end of the array?
in Algorithms edited by
853 views

1 Answer

3 votes
3 votes

we have an array of  element [ 1,3,5,8,9,2,6,7,6]

here each element represent maximum no. of jumps, let suppose we are on index 0 having value 1 so it can jump up to next 1 index { here next one index is only 1 which have value 3}.   1JUMP.

now my pointer is on 3 ,i can jump any one from next 3 index which can give the high value {next three index will be 2,3,4} having value  {5,8,9}  so i choose 9, now my pointer is on index 4.                          1 JUMP.

 

AT  pointer 4 value 9 i can jump up to next 9 index, but before to reach next 9 index, i complete traverse my array and reach at the end. so.     after CONCLUDING this jump also.    i can reach end to the array.         1 JUMP

 

SO TOTAL 3 JUMP  WE RACH AT THE END OF ARRAY.    { REMEMBER THESE ARE THE MIN JUMPS NOW YOU CAN ALSON FIND MAX JUMPS,CHOOSING THE MIN ELEMENT FROM THE ARRAY},

 

3 Comments

@jugnu1337 how can i find max no of jump?

1
1
is this que is feeels ambuguous bcoz the question should be “max no of posiions we can go ahead in forwords direction”  ? am i cooreect
0
0

@Ray Tomlinson. in last line they have ask min no of jump,  but every time if you select min value element after next jump then there should be 5 jump which is max no of jump to reach a the end of this array.

0
0

Related questions

1 vote
1 vote
1 answer
4
Anmol pratap singh asked in DS Jul 8, 2023
586 views
Anmol pratap singh asked in DS Jul 8, 2023
586 views