All problems
0248EasyArraySorting

Tightest Gauge Gaps

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1200Minimum Absolute Difference

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A calibration bench measures a batch of gauges against a reference block and records readings, the signed offset in micrometres that each gauge showed. The readings come in the order the gauges were measured, which is not necessarily sorted, and no two gauges showed the same offset.

Call the tightest gap the smallest difference between two of the recorded offsets.

Return every pair of offsets whose difference equals the tightest gap. Write each pair as [lower, higher] and list the pairs by their lower offset, smallest first. No two reported pairs share a lower offset, so that order is unambiguous.

Examples

Example 1

Input
readings = [3, 8, 1, 4, 9]
Output
[[3, 4], [8, 9]]

The tightest gap is 1 micrometre, and two pairs of offsets sit that close: 3 with 4, and 8 with 9. The pair with the lower first offset is listed first.

Example 2

Input
readings = [-7, -2, 0, -9]
Output
[[-9, -7], [-2, 0]]

The tightest gap is 2 micrometres, reached by -9 with -7 and by -2 with 0.

Example 3

Input
readings = [5, -5]
Output
[[-5, 5]]

Two gauges leave a single pair, whose difference of 10 micrometres is therefore the tightest gap.

Constraints

  • 2 <= readings.length <= 10^5
  • -10^6 <= readings[i] <= 10^6
  • All offsets in readings are distinct

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def tightest_gaps(readings: list[int]) -> list[list[int]]:
Java
public List<List<Integer>> tightestGaps(int[] readings)
September 7
Apply