19. Meeting Rooms II
mediumAsked at DropboxFind the minimum number of conference rooms needed for a set of meetings — Dropbox maps this directly to how many concurrent file-version locks the sync layer must hold at peak conflict time.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Problem
Given an array of meeting time intervals where intervals[i] = [start_i, end_i], return the minimum number of conference rooms required to hold all meetings without overlap.
Constraints
1 <= intervals.length <= 10^40 <= start_i < end_i <= 10^6
Examples
Example 1
intervals = [[0,30],[5,10],[15,20]]2Explanation: Meetings [5,10] and [15,20] can share a room, but [0,30] overlaps both and needs its own room.
Example 2
intervals = [[7,10],[2,4]]1Explanation: The two meetings do not overlap, so one room suffices.
Approaches
1. Sorted events (split starts/ends)
Separate start and end times, sort each independently. Use two pointers; when the next meeting starts before the earliest ending one, allocate a new room. Otherwise, reclaim the freed room.
- Time
- O(n log n)
- Space
- O(n)
function minMeetingRooms(intervals) {
const starts = intervals.map(i => i[0]).sort((a, b) => a - b);
const ends = intervals.map(i => i[1]).sort((a, b) => a - b);
let rooms = 0;
let endPtr = 0;
for (let i = 0; i < starts.length; i++) {
if (starts[i] < ends[endPtr]) {
rooms++;
} else {
endPtr++;
}
}
return rooms;
}Tradeoff:
2. Min-heap (priority queue)
Sort meetings by start time. Use a min-heap of end times. For each meeting, if it starts after the heap's minimum end time, reuse that room (pop). Otherwise add a new room. Heap size is the answer.
- Time
- O(n log n)
- Space
- O(n)
class MinHeap {
constructor() { this.h = []; }
push(v) {
this.h.push(v);
let i = this.h.length - 1;
while (i > 0) {
const p = Math.floor((i - 1) / 2);
if (this.h[p] <= this.h[i]) break;
[this.h[p], this.h[i]] = [this.h[i], this.h[p]];
i = p;
}
}
pop() {
const top = this.h[0];
const last = this.h.pop();
if (this.h.length > 0) {
this.h[0] = last;
let i = 0;
while (true) {
let s = i;
const l = 2*i+1, r = 2*i+2;
if (l < this.h.length && this.h[l] < this.h[s]) s = l;
if (r < this.h.length && this.h[r] < this.h[s]) s = r;
if (s === i) break;
[this.h[s], this.h[i]] = [this.h[i], this.h[s]];
i = s;
}
}
return top;
}
peek() { return this.h[0]; }
get size() { return this.h.length; }
}
function minMeetingRooms(intervals) {
intervals.sort((a, b) => a[0] - b[0]);
const heap = new MinHeap();
for (const [start, end] of intervals) {
if (heap.size > 0 && heap.peek() <= start) {
heap.pop();
}
heap.push(end);
}
return heap.size;
}Tradeoff:
Dropbox-specific tips
Dropbox often extends this to ask how you'd handle room preferences or priorities. The two-pointer approach is the cleanest to explain under time pressure; but if you have time, mentioning the heap variant shows you can generalize to weighted constraints — which matters in Dropbox's resource-scheduling context.
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 Dropbox interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →