Determine if Two Events Have Conflict — LeetCode 2446 Python Solution
- Problem
- #2446
- Pattern
- Hash Map
- Reading time
- 2 min
- Source
- leetcode.com
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
class Solution:
def haveConflict(self, event1: List[str], event2: List[str]) -> bool:
return not (event1[0] > event2[1] or event1[1] < event2[0])Complexity
| Measure | Complexity |
|---|---|
| Time | O(1) |
| Space | O(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.