Problem

Minimum Absolute Difference Pairs

Learn this problem
AGAgodaFULLTIMEONSITE INTERVIEW

Problem statement

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.

Function

minimumAbsoluteDifferencePairs(nums: int[]) → int[][]

Examples

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]]
checking account