25. Meeting Rooms II
mediumAsked at DoordashFind the minimum number of concurrent resources to cover all intervals — Doordash applies this exact pattern to Dasher shift scheduling: how many active Dashers are needed at peak overlap?
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Problem
Given an array of meeting time intervals intervals where intervals[i] = [start_i, end_i], return the minimum number of conference rooms required to hold all meetings without conflict.
Constraints
1 <= intervals.length <= 10^40 <= start_i < end_i <= 10^6Meetings may share start or end times
Examples
Example 1
intervals = [[0,30],[5,10],[15,20]]2Explanation: [0,30] overlaps with [5,10] (2 rooms needed); [15,20] reuses the room freed at 10.
Example 2
intervals = [[7,10],[2,4]]1Explanation: No overlap; one room suffices.
Approaches
1. Chronological event sweep
Create +1 events for starts and -1 events for ends; sort all events by time; track running count and record the peak.
- Time
- O(n log n)
- Space
- O(n)
function minMeetingRooms(intervals) {
const events = [];
for (const [s, e] of intervals) {
events.push([s, 1]);
events.push([e, -1]);
}
events.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
let rooms = 0, maxRooms = 0;
for (const [, delta] of events) {
rooms += delta;
maxRooms = Math.max(maxRooms, rooms);
}
return maxRooms;
}Tradeoff:
2. Min-heap of end times
Sort by start; use a min-heap of end times. For each new meeting, reuse a room if its end <= current start; otherwise allocate a new room.
- Time
- O(n log n)
- Space
- O(n)
function minMeetingRooms(intervals) {
if (!intervals.length) return 0;
intervals.sort((a, b) => a[0] - b[0]);
const ends = [];
for (const [start, end] of intervals) {
if (ends.length && ends[0] <= start) {
ends.shift();
}
ends.push(end);
ends.sort((a, b) => a - b);
}
return ends.length;
}Tradeoff:
Doordash-specific tips
Doordash frames this as: 'Given Dasher shift windows, what's the minimum fleet size for peak coverage?' They expect you to recognise both approaches (sweep-line vs heap) and justify your choice — the heap approach is often cleaner to explain for the scheduling metaphor. Watch for the tie-breaking edge: when a meeting ends exactly as another starts, should you free the room first? (Yes — mention this explicitly.) Follow-ups typically go to online streaming versions or weighted intervals.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
Practice these live with InterviewChamp.AI
Drill Meeting Rooms II and other Doordash interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →