Java: Minimum Number of Jumps to Reach End

Level : Beginner
Mentor: Shailendra Chauhan
Type : GuidedLab
Points : 10
Duration : 00:20:00

Lab Details

Problem Statement:

Given an array arr[] where each element represents the max number of steps that can be made

forward from that index. The task is to find the minimum number of jumps to reach the end of

the array starting from index 0. If the end isn’t reachable, return -1.

Input:

arr[] = {1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9}

Output:

3 (1-> 3 -> 9 -> 9)
Jump from 1st element to 2nd element as there is only 1 step.
Now there are three options 5, 8 or 9. 

If 8 or 9 is chosen then the end node 9 can be reached. So, 3 jumps are made.

Self-paced Membership
  • 22+ Courses
  • 750+ Hands-On Labs
  • 200+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A
  • 10+ Real-world Projects
  • Career Coaching
  • Email Support
Upto 66% OFF
KNOW MORE..

To get full access to all courses

Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this