> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Minimum Time Difference Python Solution

> Tested Python solution for LeetCode 539 with 15 pytest cases. Generate a practice environment with lcpy.

LeetCode 539, [Medium](/catalog/medium). Topics: [Array](/catalog/topics/array), [Math](/catalog/topics/math), [String](/catalog/topics/string), [Sorting](/catalog/topics/sorting). [View on LeetCode](https://leetcode.com/problems/minimum-time-difference/description/).

Generate this problem as a practice environment: tested reference solution, 15 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 539   # by problem number
lcpy gen -s minimum_time_difference   # by problem name
```

## 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*.

### Examples

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

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

### Constraints

* `2 <= timePoints.length <= 2 * 10^4`
* `timePoints[i]` is in the format **"HH:MM"**.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_time_difference/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/minimum_time_difference/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n log n)
    # Space: O(n)
    def find_min_difference(self, time_points: list[str]) -> int:
        minutes = sorted(int(t[:2]) * 60 + int(t[3:]) for t in time_points)
        best = 24 * 60 - (minutes[-1] - minutes[0])
        for i in range(len(minutes) - 1):
            best = min(best, minutes[i + 1] - minutes[i])
        return best
```

## Complexity

| Time | Space |
| - | - |
| O(n log n) | O(n) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.