Determine if Two Events Have Conflict - Problem
You're a busy event coordinator managing a packed schedule! You need to determine if two events scheduled for the same day have a scheduling conflict.
Given two events represented as arrays of strings:
event1 = [startTime1, endTime1]event2 = [startTime2, endTime2]
Each time is in 24-hour format (HH:MM), and both events are inclusive - meaning if one event ends at 15:30 and another starts at 15:30, they have a conflict at that exact moment.
Goal: Return true if there's any overlap between the two events, false otherwise.
Example: Event1: ["01:15", "02:00"] and Event2: ["02:00", "03:00"] โ true (they both occur at 02:00)
Input & Output
example_1.py โ Basic Overlap
$
Input:
event1 = ["01:15", "02:00"], event2 = ["02:00", "03:00"]
โบ
Output:
true
๐ก Note:
Both events occur at exactly 02:00, so there's a conflict at that moment. Since events are inclusive, touching endpoints count as conflicts.
example_2.py โ No Overlap
$
Input:
event1 = ["01:00", "02:00"], event2 = ["03:00", "04:00"]
โบ
Output:
false
๐ก Note:
Event1 ends at 02:00 and Event2 starts at 03:00. There's a gap between 02:00 and 03:00, so no conflict exists.
example_3.py โ Complete Overlap
$
Input:
event1 = ["10:00", "11:00"], event2 = ["09:30", "11:30"]
โบ
Output:
true
๐ก Note:
Event2 completely contains Event1. They overlap from 10:00 to 11:00, which is a significant conflict.
Visualization
Tap to expand
Understanding the Visualization
1
Receive Booking Requests
Person A wants 09:00-10:30, Person B wants 10:00-11:00
2
Check Overlap Conditions
Does A start before B ends? Does B start before A ends?
3
Identify Conflict
Both conditions true โ conflict from 10:00-10:30
4
Make Decision
Return true - these bookings cannot both be accepted
Key Takeaway
๐ฏ Key Insight: Two time intervals overlap if each one starts before (or when) the other ends. This creates a simple, elegant condition that works for all interval overlap problems!
Time & Space Complexity
Time Complexity
O(1)
Constant time operations for parsing and comparison
โ Linear Growth
Space Complexity
O(1)
Only using a few integer variables
โ Linear Space
Constraints
- event1.length == event2.length == 2
- event1[i].length == event2[i].length == 5
- event1[i] and event2[i] are in HH:MM format
- 0 โค HH โค 23, 0 โค MM โค 59
- The start time is always before or equal to the end time
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code