Minimum Difference
Learn this problemProblem statement
Given a set of distinct measurements taken at different times, find the minimum possible difference between any two measurements. Print all pairs of measurements that have this minimum difference in ascending order, with the pairs' elements ordered ascending. e.g., if a < b, the pair is a b. The values should have a single space between them.
Function
ibmMinimumDifference2(measurements: int[]) → int[][]
Complete the function minimumDifference in the editor.
minimumDifference has the following parameter:
int measurements[n]: an array of integers
Returns
NONE
(NOTE: NONE is specified by the orignal source. BUT, we wouldnt be able to upload the question if it returns nothing, so we made it return a 2D int arr instead :) 🥑 By spike, Dec 2024 🍉
Prints
Print the distinct pairs of measurements that have the minimum absolute difference, displayed in ascending order, with each pair separated by one space on a single line
🦥 Thank spike for the 1011st time! 💝
Examples
Example 1
measurements = [-1, 3, 6, -5, 0]return = [[-1, 0]]🍓 Source note: Corrected on 2026-07-17. The source overview overlooked the adjacent values -1 and 0.
After sorting, the measurements are [-5, -1, 0, 3, 6]. The smallest adjacent difference is 0 - (-1) = 1, so the only pair with the minimum absolute difference is [-1, 0].
Example 2
measurements = [6, 5, 4, 3, 7]return = [[3, 4],[4, 5],[5, 6],[6, 7]]Example 3
measurements = [1, 3, 5, 10]return = [[1, 3], [3, 5]]Constraints
- 2 ≤ n ≤ 10^5
- -10^9 ≤ measurements[i] ≤ 10^9
More IBM problems
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA · Seen Jul 2026
- Maximum Requests in a Time WindowOA · Seen Jul 2026
- Query Type Frequency WindowOA · Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA · Seen Jul 2026
- Spam Text ClassificationOA · Seen Jul 2026
- Count Ideal NumbersOA · Seen Jun 2026