Practice/Meta/Determine if All Intervals Have a Common Intersection
CodingMust
You are given a collection of time intervals, where each interval is represented as a pair of integers [start, end] indicating a start time and end time (both inclusive). Your task is to determine whether there exists a time period that is covered by all intervals simultaneously.
Return true if all intervals share at least one common point or range, and false otherwise.
[start, end] where start <= endExample 1:
Input: intervals = [[1, 5], [2, 6], [3, 4]] Output: true Explanation: All three intervals overlap in the range [3, 4]. Every point in this range is contained in all three intervals.
Example 2:
Input: intervals = [[1, 3], [4, 6], [2, 5]] Output: false Explanation: The first interval [1, 3] doesn't overlap with [4, 6] since 3 < 4. No single point exists in all three intervals.
Example 3:
Input: intervals = [[0, 10], [5, 8], [6, 7]] Output: true Explanation: The range [6, 7] is contained in all three intervals.
Example 4:
Input: intervals = [[1, 5], [5, 10]] Output: true Explanation: The point 5 is the boundary of both intervals and is included in both (endpoints are inclusive).