Skip to content

539. Minimum Time Difference

Array Math String Sorting

Problem - Minimum Time Difference

Medium

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.

 

Example 1:

Input: timePoints = ["23:59","00:00"]
Output: 1

Example 2:

Input: timePoints = ["00:00","23:59","00:00"]
Output: 0

 

Constraints:

  • 2 <= timePoints.length <= 2 * 104
  • timePoints[i] is in the format "HH:MM".

Solutions

1
2
3
4
5
6
class Solution:
    def findMinDifference(self, timePoints: List[str]) -> int:
        sorted_timePoints = sorted(int(val[:2]) * 60 + int(val[3:]) for val in timePoints)
        sorted_timePoints.append(sorted_timePoints[0] + 1440)

        return min(val2 - val1 for val1, val2 in pairwise(sorted_timePoints))

Submission Stats:

  • Runtime: 8 ms (71.83%)
  • Memory: 20.4 MB (55.18%)