Minimum Time Difference
Real-world version: Closest Two Times on the ClockThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def find_min_difference(timePoints: list[str]) -> int:public int findMinDifference(List<String> timePoints)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