Skip to solution
mediumDSA

How do you find the minimum number of meeting rooms required?

381 views
01

Understand the problem

Explain the meeting-rooms problem.

intervalssortingheap
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Sort meetings by start time and use a min-heap of end times; for each meeting, if the earliest end ≤ its start, reuse that room (pop), else allocate a new one (push). The heap's max size is the answer. O(n log n).

Solution ready — 2 min read

Classified // press E to declassify

04

Read the code

Sort + min-heap of end times
Run Playground
import heapq

def min_meeting_rooms(intervals):
    if not intervals:
        return 0
    intervals.sort(key=lambda x: x[0])    # by start
    heap = []                             # end times of ongoing meetings
    for start, end in intervals:
        if heap and heap[0] <= start:
            heapq.heappop(heap)           # a room freed up — reuse it
        heapq.heappush(heap, end)
    return len(heap)


# --- demo ---
print(min_meeting_rooms([[0, 30], [5, 10], [15, 20]]))   # 2
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 75 of 127 decoded in the Data Structures & Algorithms track. One more won't hurt.

Back to track