Minimum Time Difference
Medium · Arrays & Hashing · Array · Math · String · Sorting
Problem
Given a list of 24-hour clock times in "HH:MM" format, return the smallest number of minutes between any two of them.
The clock wraps around: "23:59" and "00:00" are one minute apart, not 1,439. The same time listed twice is a difference of 0.
Examples
Input: timePoints = ["23:59","00:00"] Output: 1
Going forward from 23:59, midnight is one minute away.
Input: timePoints = ["00:00","23:59","00:00"] Output: 0
00:00 appears twice, and two equal times are zero minutes apart.
Constraints
- 2 <= len(timePoints) <= 2 * 10^4
- timePoints[i] is in the format "HH:MM", from "00:00" to "23:59"
Approaches
- Compare every pair — time O(n²), space O(n)
Related problems
Start free on Cariara · Coding problems · System design studio