FastPrepFind a Good-Subarray Endpoint Pair
Problems/Find a Good-Subarray Endpoint Pair

Find a Good-Subarray Endpoint Pair

Google logoGoogle● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported task identifies this algorithmic exercise. The executable interface, bounds, deterministic tie rules, and examples are the documented practice contract.

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.

More Google problems

  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[] findGoodPair(int[] nums, int k) {
        // Write your code here.
    }

}
Checking account…