Minimum Absolute Difference

Given an array of integers, return all pairs with the minimum absolute difference. After sorting, the minimum difference must occur between adjacent elements only.

Input Format

nums = array of integers

Output Format

all pairs achieving the minimum absolute difference

Constraints

  • 2 <= nums.length <= 10^5; -10^6 <= nums[i] <= 10^6

Examples

Example 1:

Input:

nums = [4,2,1,3]

Output:

[[1,2],[2,3],[3,4]]

Explanation:

The minimum absolute difference is 1 and all adjacent sorted pairs achieve it.

Example 2:

Input:

nums = [1,3,6,10,15]

Output:

[[1,3]]

Explanation:

The smallest gap is 2, achieved by pair (1,3).

Loading...
Minimum Absolute Difference