All problems
0949MediumArrayMathStringSorting

Closest Two Times on the Clock

Tracked in this browser only
Write code

Trains the technique from

LeetCode 539Minimum Time 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.

Clock times are given as timePoints, each written as "HH:MM" on a twenty-four hour clock.

Return the fewest minutes between any two of the times, treating the clock as running round: the gap from one time to another may be measured either way about midnight, and the smaller is taken.

Examples

Example 1

Input
timePoints = ["07:42", "19:03", "07:55", "02:18"]
Output
13

Sorted, the times run 02:18, 07:42, 07:55 and 19:03. The closest pair is 07:42 and 07:55, thirteen minutes apart.

Example 2

Input
timePoints = ["22:30", "01:15"]
Output
165

Going forwards from 22:30 to 01:15 is two hours and forty-five minutes, which is shorter than going the other way round the clock.

Example 3

Input
timePoints = ["13:13", "13:13"]
Output
0

The same time appears twice, so the gap between them is nothing.

Constraints

  • 2 <= timePoints.length <= 2 * 10^4
  • timePoints[i] is written as "HH:MM" on a twenty-four hour clock

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 find_min_difference(timePoints: list[str]) -> int:
Java
public int findMinDifference(List<String> timePoints)
September 7
Apply