All Closest Pairs of Distinct Array Values

Quick Overview

All Closest Pairs of Distinct Array Values. Given distinct integers arr, find the minimum absolute difference between any two values.

All Closest Pairs of Distinct Array Values

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Given distinct integers arr, find the minimum absolute difference between any two values. Return every pair [a,b] attaining it, with a<b, and order the list of pairs increasingly. ```cpp class Solution { public: vector<vector<int>> minimumAbsDifference(vector<int>& arr); }; ``` ### Examples **Example 1:** ```text Input: arr = [8,2,5,11] Output: [[2,5],[5,8],[8,11]] Explanation: Every adjacent sorted gap is3, the minimum. ``` **Example 2:** ```text Input: arr = [-5,4,0] Output: [[0,4]] Explanation: The sorted gaps are5 and4, so only0,4 attains the minimum. ``` ### Constraints - There are 2 to 100000 distinct input integers. - Each lies in `[-1000000,1000000]`. ### Contract considerations The required sorted pair list is deterministic; output freedom is not claimed. ```hint Read the boundary condition If several pairs achieve the same least difference, how many should the output include and in what order? ``` ### Boundary reminders The required sorted pair list is deterministic; output freedom is not claimed.

Overview: All Closest Pairs of Distinct Array Values. Given distinct integers arr, find the minimum absolute difference between any two values.

Amazon logo
Amazon
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Given distinct integers arr, find the minimum absolute difference between any two values. Return every pair [a,b] attaining it, with a<b, and order the list of pairs increasingly.

class Solution {
public:
    vector<vector<int>> minimumAbsDifference(vector<int>& arr);
};

Examples

Example 1:

Input: arr = [8,2,5,11]
Output: [[2,5],[5,8],[8,11]]
Explanation: Every adjacent sorted gap is3, the minimum.

Example 2:

Input: arr = [-5,4,0]
Output: [[0,4]]
Explanation: The sorted gaps are5 and4, so only0,4 attains the minimum.

Constraints

  • There are 2 to 100000 distinct input integers.
  • Each lies in [-1000000,1000000] .

Contract considerations

The required sorted pair list is deterministic; output freedom is not claimed.

Boundary reminders

The required sorted pair list is deterministic; output freedom is not claimed.