Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Minimum Jumps to Reach End

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Minimum Jumps to Reach End. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given an integer array nums where nums[i] is the maximum jump length from index i, return the minimum number of jumps needed to reach the last index starting from index 0. If the last index cannot be reached, return -1.

Constraints

  • 1 <= len(nums) <= 10^5
  • 0 <= nums[i] <= 10^5
  • Return 0 when the array has only one element
  • Return -1 if the last index cannot be reached

Function Signature

def min_jumps(nums):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output