Minimum Time Difference

Given a list of 24-hour clock times in "HH:MM" format, return the minimum difference in minutes between any two of them. The clock wraps around midnight, so 23:59 and 00:00 are 1 minute apart.

30:00

Minimum Time Difference
medium
Free written solution
Topics
Companies

Given a list of 24-hour clock times in "HH:MM" format, return the minimum difference in minutes between any two of them. The clock wraps around midnight, so 23:59 and 00:00 are 1 minute apart.

Example 1:
Input: {"timePoints":["23:59","00:00"]}
Output: 1
Constraints:
  • 2≤timePoints.length≤2×1042 \leq \text{timePoints.length} \leq 2 \times 10^4

  • timePoints[i]\text{timePoints}[i] is in the format "HH:MM".

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"timePoints":["23:59","00:00"]}

2 time points on a 24-hour clock. The answer is the smallest gap between neighbours on the dial, including the gap across midnight.

24-hour dial

00061218

timePoints → minute

23:59
00:00
prev -1
first -1
best 1440
Variables
VariableValue
n2
DepthFunction Call
Stack empty
0/14