Find a Good-Subarray Endpoint Pair
Problem statement
Given an integer array nums and a nonnegative integer k, find two indices i < j such that |nums[i] - nums[j]| = k.
Return the lexicographically smallest valid pair [i, j]: minimize i, then j. Return [-1, -1] when no pair exists.
Function
findGoodPair(nums: int[], k: int) → int[]Examples
Example 1
nums = [1,2,4,7]k = 3return = [0,2]Case 1 exercises the documented deterministic contract.
Example 2
nums = [5,1,5]k = 0return = [0,2]Case 2 exercises the documented deterministic contract.
Example 3
nums = [8,3,12,7]k = 5return = [0,1]Case 3 exercises the documented deterministic contract.
Constraints
2 <= nums.length <= 200000.-10^9 <= nums[i] <= 10^9.0 <= k <= 2 * 10^9.