Problem · Array

Minimum Difference

Learn this problem
EasySalesforceFULLTIMEOA
See Salesforce hiring insights

Problem statement

Given a set of distinct measurements taken at different times, find the minimum absolute difference between any two measurements.

Return every pair with that minimum difference as a flattened integer array. Within each pair, place the smaller value first. Order the pairs by their first value, then by their second value.

Function

minimumDifference(measurements: int[]) → int[]

Examples

Example 1

measurements = [-1, 3, 6, -5, 0]return = [-1,0]

After sorting, the measurements are [-5,-1,0,3,6]. The adjacent differences are 4, 1, 3, and 3. The minimum is 1, produced only by the pair (-1,0), so the function returns [-1,0].

Constraints

🍎🍎

More Salesforce problems

drafts saved locally
public int[] minimumDifference(int[] measurements) {
  // write your code here
}
measurements[-1, 3, 6, -5, 0]
expected[-1,0]
checking account