Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Jumps to Reach the Last Index

Maximum Number of Jumps to Reach the Last Index asks you to move through an integer array with forward jumps between values differing by no more than target, returning the most jumps or -1 if unreachable.

Statement

You are given a 00 indexed integer array nums of length n and an integer target.

You start at index 00. In a single move, you can jump from index i to any index j such that 0≤i<j<n0 \leq i < j < n and −‘target‘≤‘nums[j]‘−‘nums[i]‘≤‘target‘-`target` \leq `nums[j]` - `nums[i]` \leq `target`.

Return the maximum number of jumps needed to reach index n−1n - 1. If it is impossible to reach index n−1n - 1, return −1-1.

Constraints:

  • 2≤2 \leq nums.length =n≤1000= n \leq 1000

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9

  • 0≤0 \leq target ≤2×109\leq 2 \times 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Jumps to Reach the Last Index

Maximum Number of Jumps to Reach the Last Index asks you to move through an integer array with forward jumps between values differing by no more than target, returning the most jumps or -1 if unreachable.

Statement

You are given a 00 indexed integer array nums of length n and an integer target.

You start at index 00. In a single move, you can jump from index i to any index j such that 0≤i<j<n0 \leq i < j < n and −‘target‘≤‘nums[j]‘−‘nums[i]‘≤‘target‘-`target` \leq `nums[j]` - `nums[i]` \leq `target`.

Return the maximum number of jumps needed to reach index n−1n - 1. If it is impossible to reach index n−1n - 1, return −1-1.

Constraints:

  • 2≤2 \leq nums.length =n≤1000= n \leq 1000

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9

  • 0≤0 \leq target ≤2×109\leq 2 \times 10^9