Problem · Array
Minimum Difference
Learn this problemProblem 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
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Final Pod Counts After LogsOA · Seen May 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
- Good Ways to Split an ArrayPHONE SCREEN · Seen May 2026
- Generate Seen Binary StringsOA · Seen May 2026
- Update Pod Counts From LogsOA · Seen May 2026
- Minimum Removals to Balance ArrayOA · Seen May 2026