#1200
Minimum Absolute Difference
newbie · 225 · lc easy +17 · verified · 75.1% accepted · 2,882 likes · top 86%
Description
You are given an array of distinct integers arr. Find every pair of elements whose absolute difference equals the smallest absolute difference among all element pairs.
Return these pairs in ascending order, where each pair [a, b] satisfies:
- Both a and b come from arr
- a < b
- b - a equals the minimum absolute difference
Example 1:
Input: arr = [4,2,1,3]
Output: [[1,2],[2,3],[3,4]]
Explanation: The minimum absolute difference is 1. List all pairs with difference equal to 1 in ascending order.
Example 2:
Input: arr = [1,3,6,10,15]
Output: [[1,3]]
Example 3:
Input: arr = [3,8,-10,23,19,-4,-14,27]
Output: [[-14,-10],[19,23],[23,27]]
Code
1
2
3