← Heap / Priority Queue

Pattern Recognition Drill

#61 — Meeting rooms II

Medium Heaps

The Problem

Given meeting intervals [start, end], find minimum conference rooms required.

What approach would you use?

Think about it before scrolling down.

Key Signals

Heap / Priority Queue

Sort by start. Min-heap of end times. If earliest end <= new start, reuse room (pop). Else add room. O(n log n).

Alt: Sorting

Separate start and end arrays, sweep-line counting overlaps. Same O(n log n), less intuitive.

Common Trap

The heap tracks the earliest-ending meeting. If it ends before the new one starts, the room is freed.

← #60 #62 →