AAlgoLoopSpaced repetition for LeetCode
EASYIntervalsLeetCode ↗

Meeting Rooms

The key idea

Sort the meetings by start time. Once sorted, two meetings conflict only if the next meeting starts before the previous one ends. So a single left-to-right scan comparing each meeting's start against the running latest end answers the whole question.

Problem

Given an array of meeting time intervals intervals where intervals[i] = [start_i, end_i], determine if a person could attend all meetings.

A person can attend every meeting only if no two meetings overlap in time. Two meetings overlap when one starts before the other ends. Touching endpoints do not count as overlap: a meeting ending at time t and another starting at time t is allowed.

Return true if the person can attend all meetings, and false otherwise.

Constraints

Examples

Input: intervals = [[0,30],[5,10],[15,20]] Output: false
Input: intervals = [[7,10],[2,4]] Output: true

Complexity

Time: O(n log n) Space: O(1)

See the full solution

410310
Step-by-step visualization
Start free →

More Intervals problems