← Interval & Math

Micro-Drill #260 — Min rooms with heap (meeting rooms II)

Interval & Math Target: 15s

Heap tracks room end times. If the earliest-ending room is free, reuse it; otherwise allocate a new one.

import heapq
intervals.sort()
rooms = []  # min-heap of end times
for start, end in intervals:
    if rooms and rooms[0] <= start:
        heapq.heappop(rooms)  # reuse room
    heapq.heappush(rooms, end)
return len(rooms)

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #259 Micro #261 →