Mid-levelMid (3–6 yrs)CodingPythonAmazonMetaBloomberg
Meeting Rooms II
Given meeting time intervals, find the minimum number of conference rooms required.
Answers use simple, clear English.
Audio N/ATime: O(n log n)Space: O(n)
Quick interview answer
Sort starts and ends separately (or use a min-heap of end times). Sweep: increment on start, decrement on end; track peak concurrent meetings.
Detailed answer
Sort starts and ends separately (or use a min-heap of end times). Sweep: increment on start, decrement on end; track peak concurrent meetings. Equivalent to maximum overlap of intervals.
Full explanation
Equivalent to maximum overlap of intervals.
Real example & use case
Office booking system sizing how many Zoom rooms to reserve for a day.
Pros & cons
Pros: O(n log n). Cons: tie-breaking when start==end needs a policy (end first).
Code example
import heapq
def min_meeting_rooms(intervals: list[list[int]]) -> int:
if not intervals: return 0
intervals.sort()
ends = []
for s, e in intervals:
if ends and ends[0] <= s:
heapq.heappop(ends)
heapq.heappush(ends, e)
return len(ends)Practice code · python (view only · no execution)
import heapq
def min_meeting_rooms(intervals: list[list[int]]) -> int:
if not intervals: return 0
intervals.sort()
ends = []
for s, e in intervals:
if ends and ends[0] <= s:
heapq.heappop(ends)
heapq.heappush(ends, e)
return len(ends)#heap#intervals