Reach the Last Index in the Fewest Jumps

Quick Overview

Find the minimum number of jumps to a reachable final array index, where each entry limits the distance of a jump from that position.

Reach the Last Index in the Fewest Jumps

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem You start at index `0` of the integer array `jumps`. From index `i`, choose an integer distance `d` and move to index `i + d`, provided that: - `0 <= d <= jumps[i]` - `i + d < jumps.length` Return the fewest jumps needed to arrive at the final index. Every allowed input guarantees that this index is reachable. ### Examples **Example 1** ```text Input: jumps = [4,1,2,1,3,0,1,0] Output: 2 ``` One jump can move from index `0` to index `4`, and the next can move from index `4` to index `7`. A single jump from the starting position cannot reach index `7`. **Example 2** ```text Input: jumps = [0] Output: 0 ``` The starting index is already the final index, so no jump is needed. ### Constraints - `1 <= jumps.length <= 10^4` - `0 <= jumps[i] <= 1000` - The final index is reachable from index `0` under the stated jump rules.

Overview: Find the minimum number of jumps to a reachable final array index, where each entry limits the distance of a jump from that position.

Amazon logo
Amazon
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
1
0

Problem

You start at index 0 of the integer array jumps. From index i, choose an integer distance d and move to index i + d, provided that:

  • 0 <= d <= jumps[i]
  • i + d < jumps.length

Return the fewest jumps needed to arrive at the final index. Every allowed input guarantees that this index is reachable.

Examples

Example 1

Input: jumps = [4,1,2,1,3,0,1,0]
Output: 2

One jump can move from index 0 to index 4, and the next can move from index 4 to index 7. A single jump from the starting position cannot reach index 7.

Example 2

Input: jumps = [0]
Output: 0

The starting index is already the final index, so no jump is needed.

Constraints

  • 1 <= jumps.length <= 10^4
  • 0 <= jumps[i] <= 1000
  • The final index is reachable from index 0 under the stated jump rules.