Problem · Array
Minimum Absolute Pair Difference
Learn this problemProblem statement
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[]) → longExamples
Example 1
values = [1,20,100,3]return = 2The closest pair is 1 and 3, whose absolute difference is 2.
Example 2
values = [8,-4,12,-5]return = 1The pair -5 and -4 has difference 1.
Example 3
values = [7,2,7]return = 0The 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
- Add Drama to Text GroupsOA · Seen Jul 2026
- Lexicographic Word FrequenciesOA · Seen Jul 2026
- Sum Multiples of 3, 5, or 7 Below NOA · Seen Jul 2026
- Coordinate Bounding BoxOA · Seen Jul 2026
- Increase Exclamations and Convert PeriodsOA · Seen Jul 2026
- Interleave Equal-Length Strings by ColumnOA · Seen Jul 2026
- Scale Ingredient QuantitiesOA · Seen Jul 2026
- Bounding Box from CoordinatesOA · Seen May 2026