Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements. Return a list of pairs in ascending order (with respect to pairs), each pair [a, b] follows: a, b are from arr, a < b, and b - a equals the minimum absolute difference of any two elements in arr.
Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements. Return a list of pairs in ascending order (with respect to pairs), each pair [a, b] follows: a, b are from arr, a < b, and b - a equals the minimum absolute difference of any two elements in arr.
Example 1:
Input: {"arr":[4,2,1,3]}
Output: [[1,2],[2,3],[3,4]]
Constraints:
2≤arr.length≤105
−106≤arr[i]≤106
All values in arr are distinct.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"arr":[4,2,1,3]}
The closest pair of numbers must be neighbours once the array is sorted, so sort first and only compare adjacent values.