Problem Description
Given two events that occur on the same day defined by their start and end times in "HH:MM" format, determine if the two events have any time conflict. A conflict exists if the events share at least one common time point.
Key Insights
- The events are inclusive, meaning if one event ends when the other begins, it is considered a conflict.
- Since times are in "HH:MM" format and are zero-padded, they can be compared as strings or converted to minutes.
- Checking for an overlap can be done by ensuring one event starts before the other event ends and vice versa.
Space and Time Complexity
Time Complexity: O(1) – The operations are constant time comparisons. Space Complexity: O(1) – Only a few variables are used regardless of input size.
Solution
The main idea is to check whether the two events overlap. Since the event times are given in "HH:MM" format, we can either compare them as strings or convert them into an integer representation (minutes since midnight) for clarity. The events conflict if:
- The start time of event1 is less than or equal to the end time of event2, and
- The start time of event2 is less than or equal to the end time of event1.
This approach uses simple condition checks with constant time operations.