File: determine-if-two-events-have-conflict/solution.py

Date: 2026-06-06

Time: 16:21

Purpose

This file solves LeetCode 2446: Determine if Two Events Have Conflict. It owns the single responsibility of checking whether two time intervals on the same day overlap.

Key Components

haseventconflict(event1, event2) -> bool

Takes two events, each represented as a [startTime, endTime] pair in "HH:MM" string format, and returns whether they overlap.

The implementation is a single expression:


return event1[0] <= event2[1] and event2[0] <= event1[1]

This is the standard interval overlap test: two intervals [a, b] and [c, d] overlap if and only if a <= d and c <= b. It's the negation of the non-overlap condition (a > d or c > b).

Patterns

Lexicographic string comparison as time comparison. The code compares "HH:MM" strings directly with <= instead of parsing them into integers or datetime objects. This works because "HH:MM" is a fixed-width, zero-padded format where lexicographic order equals chronological order (e.g., "09:30" < "10:00" < "23:59"). This is a common idiom in LeetCode solutions for time-formatted strings.

Closed-interval overlap formula. Both endpoints are inclusive — events sharing an exact boundary time (e.g., one ends at "10:00" and the other starts at "10:00") are considered conflicting. The <= (not <) enforces this.

Dependencies

Flow

1. Caller passes two lists of two "HH:MM" strings each.

2. The function performs two string comparisons and returns their conjunction.

3. No mutation, no side effects, no iteration.

Constant time and space: O(1).

Invariants

Error Handling

None. The function trusts its inputs per LeetCode conventions — no validation of format, length, or ordering. An IndexError would propagate naturally if a list had fewer than two elements.

Topics to Explore

Beliefs