Leetcode 2446: Determine if Two Events Have Conflict

grid47
grid47
Exploring patterns and algorithms
Mar 7, 2024 4 min read

Given two events, each with a start time and end time in the HH:MM format, determine if the two events overlap at any point in time. Return true if there is any overlap, otherwise return false.
Problem
Approach
Steps
Complexity
Input: Each input consists of two arrays, `event1` and `event2`. Both arrays have two string elements representing the start and end times of the respective events.
Example: event1 = ["09:00","10:00"], event2 = ["09:30","11:00"]
Constraints:
• event1.length == event2.length == 2
• event1[i].length == event2[i].length == 5
• startTime <= endTime
Output: Return `true` if there is a conflict, meaning the two events overlap in time. Otherwise, return `false`.
Example: Output: true
Constraints:
• Both input arrays are guaranteed to have exactly two elements each, representing valid time intervals.
Goal: Determine if there is an overlap between two time intervals.
Steps:
• 1. Compare the start and end times of both events.
• 2. If the start time of the second event is before or at the end time of the first event, and the end time of the second event is after or at the start time of the first event, then the events overlap.
Goal: Time intervals are given in the valid 24-hour HH:MM format.
Steps:
• startTime1 <= endTime1
• startTime2 <= endTime2
• 0 <= startTime1, startTime2 <= 23:59
• endTime1, endTime2 <= 23:59
Assumptions:
• The events are within the same day, and the times are given in valid 24-hour format.
Input: event1 = ["01:00","02:00"], event2 = ["01:30","03:00"]
Explanation: The events overlap from 01:30 to 02:00, so the answer is `true`.

Input: event1 = ["12:00","13:00"], event2 = ["14:00","15:00"]
Explanation: The events do not overlap, so the answer is `false`.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus