Skip to content
StackDecode
GreedyAnimated

Meeting Rooms

Sort and sweep to find how many rooms are needed.

Time

O(n log n)

Extra space

O(n)

Use it for

Calendar conflicts.

How it works

  1. Sort the start times and the end times separately.
  2. Walk through the starts. If a meeting starts before the earliest unfinished meeting ends, it needs a new room. Otherwise it reuses a room that has just been freed.
  3. A meeting ending exactly when another starts shares a room. The number of rooms ever needed at once is the answer. O(n log n).

Watch it run

Loading animation…