Find Indices With Index and Value Difference I

You are given a 0-indexed integer array nums having length n, an integer indexDifference, and an integer valueDifference.

Your task is to find two indices i and j, both in the range [0, n - 1], that satisfy the following conditions:

  • abs(i - j) >= indexDifference
  • abs(nums[i] - nums[j]) >= valueDifference

Return an integer array answer, where answer = [i, j] if there are two such indices, and answer = [-1, -1] otherwise. If there are multiple choices for the two indices, return any of them.

Note: i and j may be equal.

Example 1
Inputnums = [5,1,4,1], indexDifference = 2, valueDifference = 4
Output[0,3]
Indices i = 0 and j = 3 satisfy abs(0 - 3) >= 2 and abs(nums[0] - nums[3]) >= 4, so [0, 3] is valid.
Example 2
Inputnums = [2,1], indexDifference = 0, valueDifference = 0
Output[0,0]
Indices i = 0 and j = 0 satisfy abs(0 - 0) >= 0 and abs(nums[0] - nums[0]) >= 0, so [0, 0] is valid.

Constraints

  • 1 <= n == nums.length <= 100
  • 0 <= nums[i] <= 50
  • 0 <= indexDifference <= 100
  • 0 <= valueDifference <= 50

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate