Explain the meeting-rooms problem.
01
01
Understand the problem
intervalssortingheap
02
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
03
Study the solution
The solution is waiting
Give it an honest attempt first — then compare your thinking with the full walkthrough.
04
04
Read the code
Sort + min-heap of end times
Run Playgroundimport 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]])) # 205
05
Join the discussion
Discussion (0)
Sign in to join the discussion.
No responses yet. Be the first to share what you think.