Tap here to switch tabs
Problem
Submissions

Problem: Find Indices With Index and Value Difference II

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

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

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

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