Interval Overlap Checker - aloalgo

Interval Overlap Checker

Easy

You are given two intervals, interval1 and interval2, where each interval is represented as an array of two integers [start, end]. Your task is to determine if these two intervals overlap.

Two intervals overlap if they share at least one common point. For instance, [1, 5] and [3, 7] overlap because they share the range [3, 5]. Similarly, [1, 3] and [3, 5] overlap at point 3.

The start of an interval is always less than or equal to its end (start <= end).

Example 1

Inputs
interval1 = [1, 5]
interval2 = [3, 7]
Output
True
Explanation:

The intervals [1, 5] and [3, 7] overlap in the range [3, 5].

Example 2

Inputs
interval1 = [1, 2]
interval2 = [3, 4]
Output
False
Explanation:

The intervals [1, 2] and [3, 4] do not share any common points.

Example 3

Inputs
interval1 = [1, 10]
interval2 = [3, 7]
Output
True
Explanation:

The interval [3, 7] is entirely contained within [1, 10], hence they overlap.

Example 4

Inputs
interval1 = [1, 3]
interval2 = [3, 5]
Output
True
Explanation:

The intervals [1, 3] and [3, 5] touch at point 3, which counts as an overlap.

Loading...
Inputs
interval1 = [1, 5]
interval2 = [3, 7]
Output
True

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!