Off-by-one on range boundaries
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.
Build confidence with an intuition-first walkthrough focused on array fundamentals.
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 <= endTime2HH:MM format.Problem summary: 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.
Start with the most direct exhaustive search. That gives a correctness anchor before optimizing.
Pattern signal: Array
["01:15","02:00"] ["02:00","03:00"]
["01:00","02:00"] ["01:20","03:00"]
["10:00","11:00"] ["14:00","15:00"]
merge-intervals)non-overlapping-intervals)my-calendar-i)Source-backed implementations are provided below for direct study and interview prep.
// Accepted solution for LeetCode #2446: Determine if Two Events Have Conflict
class Solution {
public boolean haveConflict(String[] event1, String[] event2) {
return !(event1[0].compareTo(event2[1]) > 0 || event1[1].compareTo(event2[0]) < 0);
}
}
// Accepted solution for LeetCode #2446: Determine if Two Events Have Conflict
func haveConflict(event1 []string, event2 []string) bool {
return !(event1[0] > event2[1] || event1[1] < event2[0])
}
# Accepted solution for LeetCode #2446: Determine if Two Events Have Conflict
class Solution:
def haveConflict(self, event1: List[str], event2: List[str]) -> bool:
return not (event1[0] > event2[1] or event1[1] < event2[0])
// Accepted solution for LeetCode #2446: Determine if Two Events Have Conflict
impl Solution {
pub fn have_conflict(event1: Vec<String>, event2: Vec<String>) -> bool {
!(event1[1] < event2[0] || event1[0] > event2[1])
}
}
// Accepted solution for LeetCode #2446: Determine if Two Events Have Conflict
function haveConflict(event1: string[], event2: string[]): boolean {
return !(event1[0] > event2[1] || event1[1] < event2[0]);
}
Use this to step through a reusable interview workflow for this problem.
Two nested loops check every pair or subarray. The outer loop fixes a starting point, the inner loop extends or searches. For n elements this gives up to n²/2 operations. No extra space, but the quadratic time is prohibitive for large inputs.
Most array problems have an O(n²) brute force (nested loops) and an O(n) optimal (single pass with clever state tracking). The key is identifying what information to maintain as you scan: a running max, a prefix sum, a hash map of seen values, or two pointers.
Review these before coding to avoid predictable interview regressions.
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.