Given a list of 24-hour clock time points in "HH:MM" format, return the minimum minutes difference between any two time points in the list.
The clock wraps around at midnight, so "23:59" and "00:00" are 1 minute apart. The list can contain the same time more than once.
Function Signature
def find_min_difference(time_points: list[str]) -> int:
Rules
-
A day has 1440 minutes. Two times that are
d
minutes apart going forward are
1440 - d
minutes apart going the other way, and their difference is the smaller of the two.
-
Two equal time points have a difference of 0.
Constraints
-
2 <= len(time_points) <= 2 * 10^4
-
Each
time_points[i]
is in the format
"HH:MM"
and is a valid 24-hour time from
"00:00"
to
"23:59"
.
Examples
Input: time_points = ["23:59", "00:00"]
Output: 1
Going forward from 23:59, the clock reaches 00:00 after 1 minute. The other direction takes 1439 minutes, so the answer is 1.
Input: time_points = ["00:00", "23:59", "00:00"]
Output: 0
"00:00" appears twice, and two identical time points are 0 minutes apart.
Input: time_points = ["01:00", "02:30", "23:00"]
Output: 90
01:00 to 02:30 is 90 minutes. 23:00 to 01:00 across midnight is 120 minutes, and 02:30 to 23:00 is 1230 minutes one way or 210 the other. The smallest of these is 90.