Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Min Number of Jumps

Medium Acceptance 50.48% Points 30

You are given an array of non-negative integers nums, where each element represents the maximum jump length from that position.

Starting at index 0, your task is to return the minimum number of jumps needed to reach the last index. Return -1 if the last index cannot be reached.

Examples
Example 1

image Input: nums = [2,3,1,1,4]
Output: 2
Explanation: Jump from index 0 to index 1, then from index 1 to the last index.

Example 2

image Input: nums = [1,1,1,1]
Output: 3
Explanation: Each jump advances one step, requiring three jumps to reach the end.

Example 3

image Input: nums = [1,0,3]
Output: -1
Explanation: The jump length of 0 at index 1 makes the last index unreachable.

Constraints
    • 1 = nums.length = 104
    • 0 = nums[i] = 105
Hints
    • Hint 1: At each position, consider the range of indices you can reach from there.
    • Hint 2: Try to make each jump take you as far as possible while still minimizing the total number of jumps.
    • Hint 3: Keep track of the furthest position you can reach as you move through the array.
Topics
Dynamic Programming
Companies
Cisco Paytm
Added 16 Aug 2026 50.48% acceptance
Ln 1, Col 1Sign in to save your code
2 3 1 1 4
2