Minimum Time Difference

1. Understand the problem

1.1. Explain the main idea of the problem

We are given a list of time points in HH:MM format, representing times on a 24-hour clock.

Our task is to find the minimum difference in minutes between any two distinct positions in the list.

Rules:

  1. Each time point is between 0:00 and 3:59.
  2. We can compare any two time points, not necessarily adjacent ones in the input.
  3. The clock wraps around at midnight: after 3:59 comes 0:00.
  4. Two identical time points have a difference of .
  5. We need to return the smallest difference among all possible pairs.

Important observation:

A 24-hour clock contains exactly:

We can convert every time point into an integer representing the number of minutes elapsed since midnight.

For a time HH:MM:

For example:

time = "13:05"hour = 13minute = 5total_minutes = 13 * 60 + 5# 785

Now, instead of comparing strings, we compare integers.