Ctrl K

Closest Clock Readings

Medium
The list readings holds 24-hour clock readings in the format "HH:MM". Find the smallest difference in minutes between any two readings in the list. Time wraps around: right after "23:59" comes "00:00", so "23:58" and "00:01", for instance, are just 3 minutes apart. The difference between two readings is the shorter of the two ways around the clock. Readings may repeat.
Example 1
readings=["22:15", "07:40", "21:50"] → 25

"21:50" and "22:15" are the closest pair: 25 minutes apart.

Example 2
readings=["23:55", "00:03", "12:00"] → 8

Across midnight, "23:55" and "00:03" are only 8 minutes apart.

Example 3
readings=["09:30", "18:00", "09:30"] → 0

Two identical readings give a difference of 0.

Constraints
  • 2 ≤ len(readings) ≤ 2·10⁴
  • Each reading is a string "HH:MM" with 00 ≤ HH ≤ 23 and 00 ≤ MM ≤ 59
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsRound Prices to a Total MediumAnagram Buckets MediumBiggest Number From Pieces MediumSorted Parabola Values MediumChain of Multiples Medium
loading Python…
Input
readings=["22:15", "07:40", "21:50"]
Expected
25

Run checks the first 3 tests in your browser. Submit checks all 86 tests on the server, hidden ones included.