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
๐Ÿข Conference Room Booking System๐Ÿ“‹ Booking Requests Received๐Ÿ‘ค Person A: 09:00 - 10:30๐Ÿ‘ค Person B: 10:00 - 11:0009:0009:3010:0010:3011:0011:30Person A BookingPerson B Bookingโš ๏ธ CONFLICT ZONE๐Ÿšซ BOOKING CONFLICT DETECTEDโœ“ A starts (09:00) โ‰ค B ends (11:00)โœ“ B starts (10:00) โ‰ค A ends (10:30)Result: Cannot accept both bookings
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

n
2n
โœ“ Linear Growth
Space Complexity
O(1)

Only using a few integer variables

n
2n
โœ“ 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
Asked in
Google 15 Amazon 12 Microsoft 8 Meta 6
28.4K Views
Medium Frequency
~8 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen