Find pairs with the minimum absolute difference
Company: Microsoft
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates array manipulation, sorting-based reasoning, and the ability to generate ordered value pairs that reflect minimum absolute differences while handling ordering and duplicates.
Constraints
- Pairs are returned as [smaller, larger]
Examples
Input: ([-1, -2, -4, -5, 7, 10],)
Expected Output: [[-5, -4], [-2, -1]]
Explanation: Example pairs.
Input: ([4, 2, 1, 3],)
Expected Output: [[1, 2], [2, 3], [3, 4]]
Explanation: Several adjacent differences tie.
Input: ([1, 1, 1],)
Expected Output: [[1, 1]]
Explanation: Duplicate values give difference zero.
Input: ([5],)
Expected Output: []
Explanation: Need two values.
Hints
- Sort; the minimum difference must occur between adjacent sorted values.