Quick 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.

Find pairs with the minimum absolute difference

Company: Microsoft

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given an integer array (not necessarily sorted), find the minimum absolute difference between any two distinct elements. Return all pairs of values that achieve this minimum difference. Requirements: - Each pair should be ordered as [smaller, larger]. - Return pairs in ascending order by their first element (and then second if needed). Example: Input: [-1, -2, -4, -5, 7, 10] Output: [[-5, -4], [-2, -1]] Explanation: The minimum difference is 1, achieved by (-5, -4) and (-2, -1).

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.

Return all value pairs achieving the minimum absolute difference, ordered ascending.

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

  1. Sort; the minimum difference must occur between adjacent sorted values.

Loading coding console...