Fundamentals/Minimum Absolute Difference Pairs
← PrevNext →
Given an integer array arr, find every pair of elements [a, b] (with a <= b) whose absolute difference equals the minimum absolute difference between any two elements of arr. Return the pairs in ascending order by the smaller element.
Input
arr: array of integers
Output
A list of [a, b] pairs, each having the minimum absolute difference, in sorted order.
Examples
Example 1
Inputarr = [1, 2, 3, 4]
Output[[1, 2], [2, 3], [3, 4]]
Explanation: After sorting, every adjacent pair has difference 1, which is the minimum.
Example 2
Inputarr = [1, 3, 5, 18, 19, 25]
Output[[18, 19]]
Constraints
2 <= arr.length <= 10^5
Duplicate values are allowed and may form pairs with difference 0.