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 Description
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! 💝
Example 1:
Input: measurements = [-1, 3, 6, -5, 0]
Output: [[0,3],[3, 6]]
Explanation:NOTE: Official output could be wrong. Correct output could be [[-1,0]]. - By spike, Dec 2024 :) Official Explanation - The minimum absolute difference is 3, and the pairs with that difference are (3,6) and (0,3). When printing element pairs (i,j), they should be ordered ascending first by i and then by j.
Example 2:
Input: measurements = [6, 5, 4, 3, 7]
Output: [[3, 4],[4, 5],[5, 6],[6, 7]]
Explanation:The minimum absolute difference is 1, and the pairs with that difference are (3,4), (4,5), (5,6), and (6,7).
Example 3:
Input: measurements = [1, 3, 5, 10]
Output: [[1, 3], [3, 5]]
Explanation:The minimum absolute difference between any two elements in the array is 2, and there are two such pairs: (1, 3) and (3, 5).
- 2 ≤ n ≤ 10^5
- -10^9 ≤ measurements[i] ≤ 10^9

input:
output: