Determine if Two Events Have Conflict - 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.

A conflict happens when two events have some non-empty intersection (i.e., some moment is common to both events).

Return true if there is a conflict between two events. Otherwise, return false.

Input & Output

Example 1 — Basic Overlap
$ Input: event1 = ["01:15", "02:00"], event2 = ["01:30", "03:00"]
Output: true
💡 Note: Events overlap from 01:30 to 02:00. Since event1 starts at 01:15 (before event2 ends at 03:00) and event2 starts at 01:30 (before event1 ends at 02:00), there is a conflict.
Example 2 — No Overlap
$ Input: event1 = ["01:00", "02:00"], event2 = ["03:00", "04:00"]
Output: false
💡 Note: Events do not overlap. Event1 ends at 02:00 before event2 starts at 03:00, so there is no time conflict.
Example 3 — Edge Touch
$ Input: event1 = ["10:00", "11:00"], event2 = ["11:00", "12:00"]
Output: true
💡 Note: Events touch at exactly 11:00. Since the problem states events are inclusive, they share the moment 11:00, which counts as a conflict.

Constraints

  • event1.length == event2.length == 2
  • event1[i] and event2[i] are in HH:MM format
  • All event times are valid 24-hour format

Visualization

Tap to expand
Event Conflict Detection INPUT Event 1: 01:15 -- 02:00 Event 2: 01:30 -- 03:00 Time Overlap View 01:00 02:00 03:00 E1 E2 Overlap! ALGORITHM STEPS 1 Convert to Minutes Parse HH:MM format minutes = HH*60 + MM 2 Event 1 Times 01:15 = 1*60+15 = 75 02:00 = 2*60+0 = 120 3 Event 2 Times 01:30 = 1*60+30 = 90 03:00 = 3*60+0 = 180 4 Check Overlap Conflict if: start1 <= end2 AND start2 <= end1 75 <= 180 (true) AND 90 <= 120 (true) Result: true FINAL RESULT Output: true CONFLICT Events overlap from 01:30 to 02:00 Overlap Region: 30 min Key Insight: Two events conflict when neither ends before the other starts. Convert times to minutes for easy comparison: if start1 <= end2 AND start2 <= end1, there is an overlap. TutorialsPoint - Determine if Two Events Have Conflict | Time Conversion to Minutes Approach
Asked in
Amazon 15 Google 12 Microsoft 8
32.1K 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