Minimum Time Difference - Problem

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 time difference should be calculated as the shortest circular distance on a 24-hour clock. For example, the difference between "23:59" and "00:01" is 2 minutes (not 1438 minutes).

Note: The answer is guaranteed to be in the range [0, 720] since the maximum possible difference between any two times in a day is 12 hours (720 minutes).

Input & Output

Example 1 — Basic Case
$ Input: timePoints = ["23:59","00:01","00:03"]
Output: 2
💡 Note: The minimum difference is between "23:59" and "00:01" which is 2 minutes (going from 23:59 to 00:01 crosses midnight)
Example 2 — Same Hour
$ Input: timePoints = ["00:00","23:59","00:00"]
Output: 0
💡 Note: There are duplicate times "00:00", so the minimum difference is 0 minutes
Example 3 — Mid-day Times
$ Input: timePoints = ["12:30","14:15","13:45"]
Output: 75
💡 Note: Sorted: 12:30, 13:45, 14:15. Minimum is between 12:30 and 13:45 which is 75 minutes (1 hour 15 minutes)

Constraints

  • 2 ≤ timePoints.length ≤ 2 × 104
  • timePoints[i] is in the format "HH:MM"

Visualization

Tap to expand
Minimum Time Difference: Circular Clock Problem12:006:0018:000:0023:5900:0100:032 minOutput: 2 minutes
Understanding the Visualization
1
Input
List of time points in HH:MM format
2
Process
Convert to minutes and find minimum circular difference
3
Output
Minimum difference in minutes
Key Takeaway
🎯 Key Insight: On a circular clock, the minimum difference is always between adjacent times after sorting
Asked in
Google 15 Amazon 12 Microsoft 8
28.5K Views
Medium Frequency
~15 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen