Problem

Minimum Absolute Difference Pairs

AgodaFULLTIMEONSITE INTERVIEW

Given an integer array nums, find every pair of values whose absolute difference is equal to the minimum absolute difference among any two elements in the array.

Return the pairs with each pair written in ascending order. Return the list of pairs sorted by the first value in each pair, then by the second value.

Examples
01 · Example 1
nums = [4, 2, 10, 3, 5]
return = [[2,3],[3,4],[4,5]]

After sorting the values as [2,3,4,5,10], the minimum absolute difference is 1. The pairs with that difference are [2,3], [3,4], and [4,5].

Constraints

The source post did not specify numeric constraints.

More Agoda problems
drafts saved locally
public int[][] minimumAbsoluteDifferencePairs(int[] nums) {
  // write your code here
}
nums[4, 2, 10, 3, 5]
expected[[2,3],[3,4],[4,5]]
sign in to submit