LeetCode Problem Workspace

Determine if Two Events Have Conflict

Compare two same-day time intervals and check whether their inclusive endpoints overlap after converting HH:MM strings into sortable values.

category

2

Topics

code_blocks

6

Code langs

hub

3

Related

Practice Focus

Easy · Array plus String

bolt

Answer-first summary

Compare two same-day time intervals and check whether their inclusive endpoints overlap after converting HH:MM strings into sortable values.

Interview AiBox logo

Ace coding interviews with Interview AiBox guidance for Array plus String

Try AiBox Copilotarrow_forward

For Determine if Two Events Have Conflict, the fastest path is to treat each HH:MM value as a comparable time point and test interval overlap. Because both events are inclusive, touching at exactly one endpoint still counts as a conflict. The clean rule is that the events conflict unless one ends before the other starts.

Problem Statement

You get two arrays, each with a start time and an end time for an event that occurs on the same day. Each time is written in 24-hour HH:MM format, and each event includes both its start and end moments.

Your job is to return whether the two events share any common time. That includes the boundary case where one event ends at the exact minute the other begins, so event1 = ["01:15","02:00"] and event2 = ["02:00","03:00"] should return true because 02:00 belongs to both inclusive ranges.

Examples

Example 1

Input: event1 = ["01:15","02:00"], event2 = ["02:00","03:00"]

Output: true

The two events intersect at time 2:00.

Example 2

Input: event1 = ["01:00","02:00"], event2 = ["01:20","03:00"]

Output: true

The two events intersect starting from 01:20 to 02:00.

Example 3

Input: event1 = ["10:00","11:00"], event2 = ["14:00","15:00"]

Output: false

The two events do not intersect.

Constraints

  • event1.length == event2.length == 2
  • event1[i].length == event2[i].length == 5
  • startTime1 <= endTime1
  • startTime2 <= endTime2
  • All the event times follow the HH:MM format.

Solution Approach

Convert each HH:MM string into an ordered time value

The safest Array plus String move is to parse each HH:MM into total minutes, such as 02:00 becoming 120. This removes string-format thinking and turns the problem into a plain interval comparison, which is the interview hint hidden inside the input format.

Apply the overlap rule for inclusive intervals

After parsing, compute whether the ranges intersect by checking max(start1, start2) <= min(end1, end2). That exact <= matters because this problem counts shared endpoints as conflict, so replacing it with < breaks the example where both events meet at 02:00.

Use direct string comparison if you notice the format guarantee

Because every time is zero-padded HH:MM, lexical order matches chronological order. That means you can also solve it without numeric parsing by checking whether event1[1] < event2[0] or event2[1] < event1[0], then negating that result. This is shorter, but parsing to minutes is often clearer under interview pressure.

Complexity Analysis

Metric Value
Time Depends on the final approach
Space Depends on the final approach

This problem is constant-size, so either the parsed-minutes solution or the direct string-comparison solution runs in O(1) time and uses O(1) extra space. The only real trade-off is clarity versus brevity: minute parsing is more explicit, while string comparison depends on recognizing why zero-padded HH:MM stays correctly ordered.

What Interviewers Usually Probe

  • They mention parsing time format into an integer interval first, which points to converting HH:MM into total minutes.
  • They ask whether events that touch at one endpoint should count, which tests whether you noticed the intervals are inclusive.
  • They push on whether parsing is required, which is a hint to discuss why fixed-width HH:MM strings can be compared directly.

Common Pitfalls or Variants

Common pitfalls

  • Using a strict overlap check with < instead of <=, which incorrectly returns false when one event ends exactly when the other starts.
  • Overcomplicating an Easy problem with sorting or minute-by-minute simulation instead of comparing just two intervals.
  • Assuming all string times compare safely without explaining that the HH:MM format is zero-padded and therefore lexicographically ordered.

Follow-up variants

  • Return the length of the overlap in minutes instead of a boolean conflict flag.
  • Given many events on the same day, detect whether any pair conflicts after sorting by start time.
  • Handle times that can cross midnight, which breaks the simple same-day interval assumption in this problem.

FAQ

What is the main trick in Determine if Two Events Have Conflict?

Treat the two events as inclusive time intervals and check whether they overlap. The key boundary case is that matching endpoints still count as conflict.

Do I need to convert HH:MM to minutes for this problem?

Not strictly. Since HH:MM is zero-padded, direct string comparison works, but converting to minutes is often easier to explain and less error-prone.

Why does event1 = ["01:15","02:00"] and event2 = ["02:00","03:00"] return true?

Because the intervals are inclusive, both events contain the minute 02:00. Their intersection is not empty, so there is a conflict.

What overlap formula should I remember for this Array plus String pattern?

A reliable rule is max(start1, start2) <= min(end1, end2). If that condition holds, the intervals share at least one moment.

What is the most common bug on LeetCode 2446?

Using strict inequality and treating endpoint contact as non-overlap. In this problem, that mistake fails the exact-boundary examples.

terminal

Solution

Solution 1: String Comparison

If the start time of $event1$ is later than the end time of $event2$, or the end time of $event1$ is earlier than the start time of $event2$, then the two events will not conflict. Otherwise, the two events will conflict.

1
2
3
class Solution:
    def haveConflict(self, event1: List[str], event2: List[str]) -> bool:
        return not (event1[0] > event2[1] or event1[1] < event2[0])
Determine if Two Events Have Conflict Solution: Array plus String | LeetCode #2446 Easy