Tap here to switch tabs
Problem
Submissions

Problem: Find Indices With Index and Value Difference II

med
30 min
Try to solve the Find Indices With Index and Value Difference II problem.

Statement

You are given a 00 indexed integer array nums, and two integers indexDifference and valueDifference.

Your task is to find two indices i and j such that:

  • $ ext{abs}(i - j) \geq$ indexDifference

  • $ ext{abs}( ext{nums}[i] - ext{nums}[j]) \geq$ valueDifference

Return an integer array answer of length 22 where answer is [i,j][i, j] if such indices exist. If no such indices satisfy the given conditions, return [[-1$, −1-1]$.

If there are multiple valid pairs of indices, return any of them.

Note: i and j may be equal.

Constraints:

  • 1≤1 \leq n ==== nums.length ≤105\leq 10^5

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

  • 0≤0 \leq indexDifference ≤105\leq 10^5

  • 0≤0 \leq valueDifference ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Indices With Index and Value Difference II

med
30 min
Try to solve the Find Indices With Index and Value Difference II problem.

Statement

You are given a 00 indexed integer array nums, and two integers indexDifference and valueDifference.

Your task is to find two indices i and j such that:

  • $ ext{abs}(i - j) \geq$ indexDifference

  • $ ext{abs}( ext{nums}[i] - ext{nums}[j]) \geq$ valueDifference

Return an integer array answer of length 22 where answer is [i,j][i, j] if such indices exist. If no such indices satisfy the given conditions, return [[-1$, −1-1]$.

If there are multiple valid pairs of indices, return any of them.

Note: i and j may be equal.

Constraints:

  • 1≤1 \leq n ==== nums.length ≤105\leq 10^5

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

  • 0≤0 \leq indexDifference ≤105\leq 10^5

  • 0≤0 \leq valueDifference ≤109\leq 10^9