FastPrepMinimum Absolute Pair Difference
Problems/Minimum Absolute Pair Difference

Minimum Absolute Pair Difference

Upstart logoUpstart● EasyFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source gives the unordered-array objective and a concrete example but omits duplicate behavior, numeric bounds, and return width. The judged core task matches the visible source at about 97%.

Given an unordered integer array values, choose two elements at different indices and return the minimum possible absolute difference between their values.

Equal values at different indices are a valid pair and produce a minimum difference of 0.

Function

minimumDifference(values: int[]) → long

Examples

Example 1

values = [1,20,100,3]return = 2

The closest pair is 1 and 3, whose absolute difference is 2.

Example 2

values = [8,-4,12,-5]return = 1

The pair -5 and -4 has difference 1.

Example 3

values = [7,2,7]return = 0

The two occurrences of 7 are at different indices, so they form a valid pair with difference 0.

Constraints

  • 2 <= values.length <= 200000
  • -10^9 <= values[i] <= 10^9
  • The result fits in a signed 64-bit integer.

More Upstart problems

  • Babysitter Quote with Hourly RatesONSITE INTERVIEW · Seen Oct 2026
  • Maximum SubarrayONSITE INTERVIEW · Seen Oct 2026
  • Buffet Day GainsOA · Seen Sep 2026
All Upstart interview questionsSee Upstart hiring insights
Saved
class Solution {
    public long minimumDifference(int[] values) {
        // Write your code here.
    }
}
Checking account…