343. Find All Pairs With Minimum Absolute Difference
Find All Pairs With Minimum Absolute Difference
Given a list of distinct integers, find every pair whose absolute difference is the smallest among all possible pairs.
In each returned pair, the smaller value must appear first. Return all pairs in ascending order based on their first value.

Method Signature

List<List<Integer>> minimumAbsDifference(List<Integer> arr)

Parameters

  • arr contains distinct integers.

Return Value

Return all pairs whose difference equals the minimum absolute difference between any two values in arr.
  • Each pair is returned as [a, b], where a < b.
  • The returned pairs must be ordered by ascending a.

Constraints

  • 2 <= arr.size() <= 100,000
  • -1,000,000 <= arr.get(i) <= 1,000,000
  • All values in arr are distinct.

Examples

Example 1

Method call: minimumAbsDifference(arr = [9, 2, 6, 4])
Output: [[2, 4], [4, 6]]
Explanation: The minimum absolute difference is 2. The pairs having this difference are [2, 4] and [4, 6].

Example 2

Method call: minimumAbsDifference(arr = [20, 5, 13, 1])
Output: [[1, 5]]
Explanation: The smallest difference is 4, produced only by [1, 5].

Example 3

Method call: minimumAbsDifference(arr = [-8, 14, -3, 19, 7, 2])
Output: [[-8, -3], [-3, 2], [2, 7], [14, 19]]
Explanation: The minimum absolute difference is 5, and every returned pair has that difference.


Please use Laptop/Desktop or any other large screen to add/edit code.