codebrew.ai

Meeting Rooms II

The peak number of simultaneous meetings is the number of rooms needed.

Approach

Sort meetings by start, and keep a min-heap of end times of ongoing meetings. For each meeting, pop any that have ended before it starts, then push its end; the heap's max size over the run is the room count. A sorted-starts/sorted-ends two-pointer sweep also works.

Time complexity

O(n log n)

Space complexity

O(n)

Common mistake

Comparing each meeting to all others (O(n²)) rather than tracking active meetings with a heap.

See it run, step by step

Generate an interactive lesson for Meeting Rooms II — trace every variable and watch the algorithm execute until it clicks.

Start a lesson on Meeting Rooms II

Related problems