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.

Stuck? AI Nudge Available

Get a conceptual hint to guide your logic without spoiling the final implementation.

03

Study the solution

The solution is waiting

Give it an honest attempt first — then compare your thinking with the full walkthrough.

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.