Minimum Time Difference

Medium Topics Company Tags

Each string in timePoints is a valid time on a 24-hour clock, written as HH:MM. Choose two different entries and return the smallest distance between their times, measured in minutes around the clock. The distance may cross midnight. Two entries with identical times have distance 0.

Example 1:

Input: timePoints = ["23:50","00:10"]

Output: 20

Explanation: From 23:50 to midnight takes 10 minutes, and reaching 00:10 takes 10 more. The shorter distance is 20 minutes.

Example 2:

Input: timePoints = ["12:15","12:15"]

Output: 0

Explanation: The two entries represent the same clock time, so their distance is 0 minutes.

Example 3:

Input: timePoints = ["06:00","18:00"]

Output: 720

Explanation: The times are exactly half a day apart. Either direction around the clock takes 720 minutes.

Constraints:

  • 2 <= timePoints.length <= 20000
  • Every entry is exactly five characters in HH:MM format.
  • Hours range from 00 to 23; minutes range from 00 to 59.


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.