Determine if Two Events Have Conflict — LeetCode 2446 Python Solution

EasyArrayString
Problem
#2446
Pattern
Hash Map
Reading time
2 min

The problem

You are given two arrays of strings that represent two inclusive events that happened on the same day, event1 and event2, where: event1 = [startTime1, endTime1] and event2 = [startTime2, endTime2]. Event times are valid 24 hours format in the form of HH:MM.

Example

Input
event1 = ["01:15","02:00"], event2 = ["02:00","03:00"]
Output
true
Explanation
The two events intersect at time 2:00.

Python solution

Python
class Solution:
    def haveConflict(self, event1: List[str], event2: List[str]) -> bool:
        return not (event1[0] > event2[1] or event1[1] < event2[0])

Complexity

MeasureComplexity
TimeO(1)
SpaceO(1) auxiliary

Pattern: Hash Map

Trade memory for time: remember what you have seen so the second pass never happens. LeetCode 2446. Determine if Two Events Have Conflict is filed here because the reference solution below belongs to the algorithm family this hub collects, even though its LeetCode tags point elsewhere.

The hash map guide has the Python template for the pattern and the 709 LeetCode problems that use it.

Related problems

Frequently asked questions

How hard is LeetCode 2446. Determine if Two Events Have Conflict?
LeetCode 2446. Determine if Two Events Have Conflict is rated Easy on LeetCode.
What is the time complexity of LeetCode 2446. Determine if Two Events Have Conflict?
The Python solution on this page runs in O(1).
What is the space complexity of LeetCode 2446. Determine if Two Events Have Conflict?
The Python solution on this page uses O(1) auxiliary space.
What topics does LeetCode 2446. Determine if Two Events Have Conflict cover?
LeetCode 2446. Determine if Two Events Have Conflict is tagged Array and String on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview