All Blind 75 questions

Meeting Rooms II

FreeIntervalsMedium67 of 75

The problem

Find the minimum rooms needed for meeting intervals with start < end. A room becomes reusable at the meeting’s end time.

Example

[[1, 5], [2, 4], [4, 6]] → 2

Need a hint?

The answer is the largest number of simultaneous active meetings.

Write pseudocode, trace the example, or note an edge case. This scratchpad does not run code.

Notes stay in this browser when storage is available.

Read the solution approach

Sort meetings by start. Maintain a min-heap of active end times. Before a meeting begins, pop all ends ≤ its start. Push its end and record the maximum heap size. Removing every finished meeting keeps the heap equal to actual occupancy.

Complexity

O(n log n) time and O(n) space.

Before moving on, explain why the algorithm is correct and trace a boundary case without looking at the approach.