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.
Constraints
2 <= numbers.length <= 10^5.-10^9 <= numbers[i] <= 10^9.- All values in
numbersare distinct.
Source note: These two source-faithful panels preserve the complete March 12 Adobe OA task and its solution notes.