Find pairs with the minimum absolute difference
Company: Microsoft
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: 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.
Read the full Microsoft Machine Learning Engineer interview experience this question came from
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.
Hints
- Sort; the minimum difference must occur between adjacent sorted values.