FastPrepFastPrep
Problem Brief

Minimum Difference

FULLTIMEOA
See IBM online assessment and hiring insights

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! πŸ’

1Example 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.

2Example 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).

3Example 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).

Constraints

Limits and guarantees your solution can rely on.

  • 2 ≀ n ≀ 10^5
  • -10^9 ≀ measurements[i] ≀ 10^9
public int[][] ibmMinimumDifference2(int[] measurements) {
  // write your code here
}
Input

measurements

[-1, 3, 6, -5, 0]

Output

[[0,3],[3, 6]]

Sign in to submit your solution.