Tap here to switch tabs
Problem
Submissions

Problem: Find Indices With Index and Value Difference II

Find Indices With Index and Value Difference II asks you to return two indices with enough separation in position and value, or negative one, negative one if none qualifies. Same indices are allowed.

Statement

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

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

  • abs(i - j) ≥ indexDifference

  • abs(nums[i] - nums[j]) ≥ valueDifference

Return an integer array answer of length 2, where answer is [i, j] if such indices exist. If no pair of indices satisfies both conditions, return [-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

Find Indices With Index and Value Difference II asks you to return two indices with enough separation in position and value, or negative one, negative one if none qualifies. Same indices are allowed.

Statement

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

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

  • abs(i - j) ≥ indexDifference

  • abs(nums[i] - nums[j]) ≥ valueDifference

Return an integer array answer of length 2, where answer is [i, j] if such indices exist. If no pair of indices satisfies both conditions, return [-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