Closest Number Pairs
Problem statement
Given an integer array numbers, find the minimum absolute difference between any two values.
Return every pair that has this minimum difference as a two-dimensional integer array. Within each pair, place the smaller value first. Order the returned pairs by their first value in ascending order.
Function
closestNumberPairs(numbers: int[]) → int[][]Examples
Example 1
numbers = [4,2,1,3]return = [[1,2],[2,3],[3,4]]After sorting, the array is [1,2,3,4]. Every adjacent difference is 1, so all three adjacent pairs are returned.
Example 2
numbers = [-10,-3,0,5]return = [[-3,0]]The sorted adjacent differences are 7, 3, and 5. Only [-3,0] has the minimum difference.
Example 3
numbers = [6,2,4,10]return = [[2,4],[4,6]]Sorting gives [2,4,6,10]. The adjacent differences are 2, 2, and 4. The smallest difference is 2, so return [[2,4],[4,6]].
Constraints
2 <= numbers.length <= 10^5.-10^9 <= numbers[i] <= 10^9.- All values in
numbersare distinct.
Source note: These English source panels preserve the temperature task and examples from the January 14 Adobe OA report.