easy +10 pts

Schedule conflict check

Detect overlapping time intervals from a list of (start, end) tuples.

You are given a list of time intervals, where each interval is a tuple `(start, end)` representing a time period. The times are given as strings in 24-hour format `"HH:MM"` (e.g., `"09:30"`, `"23:59"`). All intervals have `start < end` and are within the same day. Implement the function `has_conflict(intervals)` that returns `True` if there is at least one pair of intervals that overlap (including touching at the same time), and `False` otherwise. **Function signature:** `def has_conflict(intervals: list[tuple[str, str]]) -> bool:` **Notes:** - The list may be empty (no intervals → no conflict). - Two intervals conflict if they share any time instant. For example, `("10:00", "12:00")` and `("12:00", "13:00")` DO conflict because `12:00` is shared (touching at the boundary).

Constraints

1. `0 <= len(intervals) <= 10^4` 2. Each `start` and `end` is a string in `"HH:MM"` (00:00 to 23:59). 3. For each interval, `start < end` lexicographically (which is equivalent to chronologically for this format). 4. You may assume the input is valid; no need to parse dates or handle timezones. 5. Time complexity expectation: O(n log n) if sorting is used.

Example

>>> has_conflict([("09:00", "10:30"), ("10:30", "11:30")])
True
>>> has_conflict([("09:00", "10:30"), ("10:31", "11:30")])
False
>>> has_conflict([])
False
>>> has_conflict([("08:00", "09:00"), ("09:00", "10:00")])
True
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Convert each time string to minutes after midnight for easy comparison.
Sort the intervals by start time, then check if the previous interval's end is greater than the current interval's start.
Remember that touching at the boundary (end == start) is considered a conflict.
An empty list or a single interval has no conflicts.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.