AlgoMaster Logo

Meeting Rooms

easyFrequency5 min readUpdated June 23, 2026

Understanding the Problem

We're given a list of meetings, each with a start and end time, and we need to figure out if any two meetings overlap. If they do, a person can't attend all of them, so we return false. If no meetings overlap, we return true.

Two meetings overlap when one starts before the other ends. On a timeline, if meeting A runs from 1 to 5 and meeting B runs from 3 to 7, there's a conflict between time 3 and 5. If we sort the meetings by start time, we only need to check consecutive meetings for overlap. When every consecutive pair is conflict-free, each meeting starts at or after the previous one ends, and chaining those inequalities shows that any meeting also starts at or after every earlier meeting ends. So a single conflict anywhere in the list always shows up as a conflict between some adjacent pair.

Key Constraints:

  • 0 <= intervals.length <= 10^4 → With n up to 10,000, an O(n^2) brute force checks up to 50 million pairs, which is slow. An O(n log n) sorting approach handles this size comfortably.
  • 0 <= start_i < end_i <= 10^6 → Start is always strictly less than end, so every meeting has a positive duration. There are no zero-length or inverted intervals to handle. The values fit in a 32-bit integer, so overflow is not a concern.

Approach 1: Brute Force

Intuition

Compare every pair of meetings and check whether they overlap. Two meetings [s1, e1] and [s2, e2] overlap when each starts before the other ends, which is the condition s1 < e2 and s2 < e1. If any pair satisfies it, a person cannot attend both, so the answer is false.

This checks n*(n-1)/2 pairs, so it gets slow as the list grows, but it needs no sorting and works as a baseline.

Algorithm

  1. For each meeting at index i, compare it with every meeting at index j > i.
  2. Two meetings overlap if intervals[i][0] < intervals[j][1] and intervals[j][0] < intervals[i][1].
  3. If any pair overlaps, return false.
  4. If no overlapping pair is found, return true.

Example Walkthrough

1Start: compare every unordered pair (i, j) with j > i for overlap
[1, 5]
[10, 15]
[6, 9]
115
1/5

Code

The brute force checks many pairs that cannot possibly conflict. Sorting the meetings into chronological order removes that waste, because then only neighboring meetings need to be compared.

Approach 2: Sorting

Intuition

Sorting the meetings by start time guarantees that any conflict surfaces between two adjacent meetings. After sorting, each meeting only needs to be compared against the one right before it: if the current meeting starts before the previous one ends, that is an overlap. A single pass through the sorted array settles the question.

Algorithm

  1. Sort the intervals by their start time.
  2. Iterate through the sorted intervals starting from index 1.
  3. For each meeting, check if its start time is less than the previous meeting's end time.
  4. If yes, return false (overlap detected).
  5. If we finish the loop without finding any overlap, return true.

Example Walkthrough

1Input: [[5,10],[0,5],[15,20]] (unsorted)
[5, 10]
[0, 5]
[15, 20]
020
1/5

Code