Report every closest pair
transcript
Sort the values, and look at neighbours. It passes the samples. The judge says wrong answer. It looks right on every sample you have.
Here are four of the values. Twelve and thirteen have a gap of one. Fifteen and sixteen also have a gap of one. Two pairs share the smallest gap, so both must be reported.
The slip is to keep only the first closest pair. The statement asks for every pair at the smallest gap. So keep each pair that ties. A tie is the case the samples rarely contain.
A stress test compares it with a slow twin. The very first seed fails. Two hundred and seventy of a thousand lists fail. The slow twin finds both pairs. The fast one finds one.
Use a small range of values. Then many gaps are equal. Ties show up in the first few tests.
Samples rarely have ties. Random small lists do. Full breakdown in the lecture.