Minimum Absolute Difference
Real-world version: Tightest Gauge GapsThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def tightest_gaps(readings: list[int]) -> list[list[int]]:public List<List<Integer>> tightestGaps(int[] readings)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's