Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Jumps to Reach the Last Index

med
30 min
Try to solve the Maximum Number of Jumps to Reach the Last Index problem.

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 ≤2imes109\leq 2 imes 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Jumps to Reach the Last Index

med
30 min
Try to solve the Maximum Number of Jumps to Reach the Last Index problem.

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 ≤2imes109\leq 2 imes 10^9