Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

186. Jump Game II

MediumDay 55 of 60Greedy & Intervals

You start at index 0 of nums, where nums[i] is the longest forward jump allowed from index i. It is guaranteed that the last index can be reached. Return the minimum number of jumps needed to get there.

Example 1
Input: nums = [2,3,1,1,4]
Output: 2
Jump to index 1, then jump 3 steps to the last index.
Example 2
Input: nums = [2,3,0,1,4]
Output: 2
Constraints
  • 1 <= nums.length <= 10^4
  • 0 <= nums[i] <= 1000
  • The last index is always reachable
Hints
Frequently asked at: Amazon, Google, Adobe
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min