Determine if Two Events Have Conflict solution and explanation
9 more videos on this problem
2446. Determine if Two Events Have Conflict | Leetcode Weekly 316 | LeetCode 2446Bro Coders · 7:53 · 1K views
Leetcode Weekly contest 316 - Easy - Determine if Two Events Have ConflictPrakhar Agrawal · 7:44 · 574 views
Determine if Two Events Have Conflict | leetcode Weekly 316 | Leetcode EasyBinaryMagic · 11:27 · 528 views
2446. Determine if Two Events Have Conflict || Leetcode Contest Easy || Math || CPPCoding Techniques with Komal | Newton School · 14:56 · 478 views
Leetcode 2446: Determine if Two Events Have ConflictAlgorithms Casts · 13:53 · 456 views
2446. Determine if Two Events Have Conflict (Leetcode Easy)Programming Live with Larry · 4:04 · 451 views
Determine if Two Events Have Conflict - Intervals - Leetcode 2446 - PythonCheatCode Ninja · 2:19 · 368 views
2446 Determine if Two Events Have Conflict Leetcode Weekly contest 316Ashutosh sharma · 8:30 · 279 views
Leetcode Weekly Contest 316 | PROBLEM 2446 , 2447 , 2448 | BINARY SEARCHcode Explainer · 16:12 · 208 views
Determine if Two Events Have Conflict #java #StringArray#javaInterview #interviewQuestion #leetcodeCodeVia · 6:34 · 191 views
The 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]andevent2 = [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.
Example 1:
Input: event1 = ["01:15","02:00"], event2 = ["02:00","03:00"] Output: true Explanation: The two events intersect at time 2:00.
Example 2:
Input: event1 = ["01:00","02:00"], event2 = ["01:20","03:00"] Output: true Explanation: The two events intersect starting from 01:20 to 02:00.
Example 3:
Input: event1 = ["10:00","11:00"], event2 = ["14:00","15:00"] Output: false Explanation: The two events do not intersect.
Constraints:
event1.length == event2.length == 2event1[i].length == event2[i].length == 5startTime1 <= endTime1startTime2 <= endTime2- All the event times follow the
HH:MMformat.
Approach overview
Problem Overview: You are given two events where each event contains a start and end time in HH:MM format. The goal is to determine whether the two time intervals overlap. If any portion of the time ranges intersects, the events are considered to be in conflict.
Approach 1: Convert Times to Minutes (O(1) time, O(1) space)
This approach converts each HH:MM time string into the total number of minutes from midnight. Split the string into hours and minutes, compute hours * 60 + minutes, and store the numeric values. Once both events are represented as integer ranges, checking overlap becomes a simple interval comparison: two events conflict if start1 ≤ end2 and start2 ≤ end1. This technique removes string handling complexity and turns the problem into a basic numeric comparison.
Because each event contains only two timestamps, the computation runs in constant time. This approach is often preferred when working with time calculations or when the problem later expands to require arithmetic on times. The method relies only on basic operations on a small array of values and simple parsing from a string.
Approach 2: Direct String Comparison (O(1) time, O(1) space)
The HH:MM format is lexicographically ordered. That means standard string comparison already preserves chronological order. Instead of converting to integers, you can directly compare the time strings. The same interval overlap rule applies: if event1.start ≤ event2.end and event2.start ≤ event1.end, the events conflict.
This works because the format always contains two digits for hours and minutes, ensuring correct lexical ordering. For example, "09:30" < "10:00" evaluates correctly with normal string comparison. This method avoids parsing entirely and produces a clean, minimal solution with just a few comparisons.
Since each comparison involves fixed-length strings and there are only two intervals, the time complexity remains constant. Space complexity is also constant because no additional structures are required.
Recommended for interviews: Interviewers typically expect the interval-overlap insight first: two intervals intersect unless one ends before the other begins. Either implementation is acceptable. Converting times to minutes demonstrates clear reasoning about time representation, while direct string comparison shows awareness of how formatted timestamps behave lexicographically. Mentioning both approaches shows strong problem-solving depth.
Approach 1: Approach 1: Convert Times to Minutes
This approach involves converting the time given in HH:MM format into minutes since the start of the day for easier comparison. By describing times in a single unit, it simplifies determining if time intervals overlap. Once converted, you can easily check for overlap between the two events by seeing if the start time of one event is within the duration of the other event.
def to_minutes(time):
return int(time[:2]) * 60 + int(time[3:])
def have_conflict(event1, event2):
start1, end1 = to_minutes(event1[0]), to_minutes(event1[1])
start2, end2 = to_minutes(event2[0]), to_minutes(event2[1])
return not (end1 < start2 or end2 < start1)public class EventConflict {
public static int toMinutes(String time) {
return Integer.parseInt(time.substring(0, 2)) * 60 + Integer.parseInt(time.substring(3, 5));
}
public static boolean haveConflict(String[] event1, String[] event2) {
int start1 = toMinutes(event1[0]);
int end1 = toMinutes(event1[1]);
int start2 = toMinutes(event2[0]);
int end2 = toMinutes(event2[1]);
return !(end1 < start2 || end2 < start1);
}
}#include <iostream>
#include <vector>
int toMinutes(const std::string& time) {
return (time[0] - '0') * 600 + (time[1] - '0') * 60 + (time[3] - '0') * 10 + (time[4] - '0');
}
bool haveConflict(std::vector<std::string>& event1, std::vector<std::string>& event2) {
int start1 = toMinutes(event1[0]);
int end1 = toMinutes(event1[1]);
int start2 = toMinutes(event2[0]);
int end2 = toMinutes(event2[1]);
return !(end1 < start2 || end2 < start1);
}function toMinutes(time) {
return parseInt(time.substring(0, 2), 10) * 60 + parseInt(time.substring(3, 5), 10);
}
function haveConflict(event1, event2) {
const start1 = toMinutes(event1[0]);
const end1 = toMinutes(event1[1]);
const start2 = toMinutes(event2[0]);
const end2 = toMinutes(event2[1]);
return !(end1 < start2 || end2 < start1);
}#include <stdbool.h>
#include <stdlib.h>
int toMinutes(char* time) {
int hours = (time[0] - '0') * 10 + (time[1] - '0');
int minutes = (time[3] - '0') * 10 + (time[4] - '0');
return hours * 60 + minutes;
}
bool haveConflict(char** event1, char** event2) {
int start1 = toMinutes(event1[0]);
int end1 = toMinutes(event1[1]);
int start2 = toMinutes(event2[0]);
int end2 = toMinutes(event2[1]);
return !(end1 < start2 || end2 < start1);
}using System;
public class EventConflict {
public static int ToMinutes(string time) {
return int.Parse(time.Substring(0, 2)) * 60 + int.Parse(time.Substring(3, 2));
}
public static bool HaveConflict(string[] event1, string[] event2) {
int start1 = ToMinutes(event1[0]);
int end1 = ToMinutes(event1[1]);
int start2 = ToMinutes(event2[0]);
int end2 = ToMinutes(event2[1]);
return !(end1 < start2 || end2 < start1);
}
}This Python function uses slicing and integer conversion to convert the time into minutes. It then checks the time intervals for an overlap and returns the result.
Time Complexity: O(1).
Space Complexity: O(1).
Approach 2: Approach 2: Direct String Comparison
This approach directly compares the start and end times as strings, taking advantage of lexical comparison in HH:MM format, where times can be compared directly as strings. This approach is particularly simple because the format ensures that lexicographical order corresponds to chronological order.
def have_conflict(event1, event2):
if event1[1] < event2[0] or event2[1] < event1[0]:
return False
return Truepublic class EventConflict {
public static boolean haveConflict(String[] event1, String[] event2) {
if (event1[1].compareTo(event2[0]) < 0 || event2[1].compareTo(event1[0]) < 0) {
return false;
}
return true;
}
}#include <string>
#include <vector>
bool haveConflict(std::vector<std::string>& event1, std::vector<std::string>& event2) {
if (event1[1] < event2[0] || event2[1] < event1[0]) {
return false;
}
return true;
}function haveConflict(event1, event2) {
if (event1[1] < event2[0] || event2[1] < event1[0]) {
return false;
}
return true;
}#include <stdbool.h>
#include <string.h>
bool haveConflict(char** event1, char** event2) {
if (strcmp(event1[1], event2[0]) < 0 || strcmp(event2[1], event1[0]) < 0) {
return false;
}
return true;
}using System;
public class EventConflict {
public static bool HaveConflict(string[] event1, string[] event2) {
if (string.Compare(event1[1], event2[0]) < 0 || string.Compare(event2[1], event1[0]) < 0) {
return false;
}
return true;
}
}Python's lexicographical string comparison handles time comparisons accurately for this problem, ensuring precise detection of event overlaps quickly without conversions.
Time Complexity: O(1).
Space Complexity: O(1).
Approach 3: String Comparison
If the start time of event1 is later than the end time of event2, or the end time of event1 is earlier than the start time of event2, then the two events will not conflict. Otherwise, the two events will conflict.

The time complexity is O(1), and the space complexity is O(1).
function haveConflict(event1: string[], event2: string[]): boolean {
return !(event1[0] > event2[1] || event1[1] < event2[0]);
}func haveConflict(event1 []string, event2 []string) bool {
return !(event1[0] > event2[1] || event1[1] < event2[0])
}impl Solution {
pub fn have_conflict(event1: Vec<String>, event2: Vec<String>) -> bool {
!(event1[1] < event2[0] || event1[0] > event2[1])
}
}Complexity comparison
| Approach | Complexity |
|---|---|
| Approach 1: Convert Times to Minutes | Time Complexity: O(1). |
| Approach 2: Direct String Comparison | Time Complexity: O(1). |
| String Comparison | – |
Complexity analysis
| Approach | Time | Space | When to Use |
|---|---|---|---|
| Convert Times to Minutes | O(1) | O(1) | When you want numeric comparison or expect additional time calculations |
| Direct String Comparison | O(1) | O(1) | When timestamps are guaranteed to follow HH:MM format and quick comparison is sufficient |
Frequently asked questions
Is Determine if Two Events Have Conflict easy or hard?
Determine if Two Events Have Conflict is categorized as an Easy problem. The challenge focuses on recognizing the interval overlap rule and implementing simple comparisons rather than complex algorithms or data structures.
Determine if Two Events Have Conflict Python/Java solution
Python and Java implementations typically follow the same logic: either convert HH:MM strings into minutes using parsing or directly compare the strings. After conversion or comparison, apply the interval overlap condition to determine whether the events conflict.
How to solve Determine if Two Events Have Conflict in O(1)?
Convert each HH:MM timestamp into minutes from midnight or compare the strings directly. After that, apply the interval overlap rule: if event1.start ≤ event2.end and event2.start ≤ event1.end, the events conflict. Because only four timestamps are processed, the solution runs in constant time.
What is the best approach for Determine if Two Events Have Conflict?
The best approach checks interval overlap using the condition start1 ≤ end2 and start2 ≤ end1. You can either convert times to total minutes or compare the HH:MM strings directly. Both approaches run in O(1) time and O(1) space because the input size is fixed.
Is Determine if Two Events Have Conflict asked at Google/Amazon/Meta?
Interval overlap and time comparison problems frequently appear in interviews at companies like Amazon, Google, and Meta. While this exact problem may vary, the core concept of checking overlapping intervals is a common interview pattern.
What data structure is used in Determine if Two Events Have Conflict?
The problem mainly uses arrays to store start and end times and simple string manipulation for parsing. No advanced data structures are required, making it a straightforward interval comparison task.
What is the time complexity of Determine if Two Events Have Conflict?
The time complexity is O(1). The problem only involves comparing two intervals with a fixed number of timestamps, so the number of operations does not grow with input size. Space complexity is also O(1).
