FastPrepFewest Jumps to the End or Stuck
Problems/Fewest Jumps to the End or Stuck

Fewest Jumps to the End or Stuck

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem asks for the fewest jumps from the first index to the last, where each value is the longest jump allowed from that index, and -1 when the last index cannot be reached. Its source is an Adobe interview report that names its question only as a variant of a well-known jump problem and does not say what the variant changed. Most of the report is about inputs the interviewer kept trying that broke the stated constraints; the candidate wrote a quadratic and then a linear solution and described how the approach would have to change for such inputs.

Our choices: unreachable ends are allowed and return -1 (one way to accept inputs the usual version rules out), a value of 0 blocks movement, at most 3000 values from 0 to 3000, and new examples.

The judged task matches the report at about 60%.

You start at index 0 of the array nums. From index i you may jump forward by any number of steps from 1 to nums[i] (a value of 0 means you cannot move from there).

Return the fewest jumps needed to reach the last index. If the last index cannot be reached, return -1. If the array has one element, you are already there and the answer is 0.

Function

minJumps(nums: int[]) → int

Examples

Example 1

nums = [2,4,1,1,0,2]return = 2

From index 0 jump 1 step to index 1, then 4 steps to index 5: 2 jumps. Jumping as far as possible from index 0 (to index 2) leads through index 3 to the 0 at index 4 and gets stuck there.

Example 2

nums = [1,0,3]return = -1

Index 0 reaches only index 1, whose value is 0, so index 2 can never be reached: -1.

Example 3

nums = [5]return = 0

With one element you are already at the end: 0 jumps.

Constraints

  • 1 <= nums.length <= 3000
  • 0 <= nums[i] <= 3000

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public int minJumps(int[] nums) {
    // Write your code here.
}
Checking account…