Practice/Amazon/Leetcode 1200. Minimum Absolute Difference
CodingMust
Given an array of distinct integers, find all pairs of elements that have the minimum absolute difference among all possible pairs. Return the pairs in ascending order, where each pair is also sorted in ascending order.
The absolute difference between two numbers a and b is |a - b|.
Example 1:
Input: arr = [4, 2, 1, 3] Output: [[1,2], [2,3], [3,4]] Explanation: After sorting, we get [1,2,3,4]. The minimum absolute difference is 1, which occurs between consecutive pairs (1,2), (2,3), and (3,4).
Example 2:
Input: arr = [1, 3, 6, 10, 15] Output: [[1,3]] Explanation: After sorting, the array remains [1,3,6,10,15]. The differences between consecutive elements are 2, 3, 4, and 5. The minimum is 2, occurring only between 1 and 3.
Example 3:
Input: arr = [3, 8, -10, 23, 19, -4, -14, 27] Output: [[-14,-10], [19,23], [23,27]] Explanation: After sorting: [-14,-10,-4,3,8,19,23,27]. The minimum difference is 4, occurring three times in the sorted array.