20. Meeting Rooms II
mediumAsked at AsanaFind the minimum number of meeting rooms required to host all meetings without conflicts — Asana surfaces this when its calendar-integration feature must allocate the fewest concurrent task-review slots across a team.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Problem
Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required to accommodate all meetings without overlap.
Constraints
1 <= intervals.length <= 10^40 <= starti < endi <= 10^6
Examples
Example 1
intervals = [[0,30],[5,10],[15,20]]2Explanation: Meetings [0,30] and [5,10] overlap — need 2 rooms. [15,20] reuses the room freed at 10.
Example 2
intervals = [[7,10],[2,4]]1Explanation: No overlap — one room suffices.
Approaches
1. Separate start/end sorted arrays
Sort starts and ends independently. Use two pointers: if the next start is before the earliest end, allocate a room; otherwise reuse one.
- 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 of end times (optimal intuition)
Sort by start. Maintain a min-heap of meeting end times. For each new meeting, if its start >= heap minimum, pop (reuse room); otherwise push (new room). Heap size = rooms needed.
- Time
- O(n log n)
- Space
- O(n)
function minMeetingRooms(intervals) {
if (intervals.length === 0) return 0;
intervals.sort((a, b) => a[0] - b[0]);
// Min-heap simulated with a sorted array (acceptable for interview)
const heap = [];
function heapPush(val) {
heap.push(val);
heap.sort((a, b) => a - b);
}
function heapPop() {
return heap.shift();
}
heapPush(intervals[0][1]);
for (let i = 1; i < intervals.length; i++) {
const [start, end] = intervals[i];
if (heap[0] <= start) {
heapPop();
}
heapPush(end);
}
return heap.length;
}Tradeoff:
Asana-specific tips
Asana interviewers often frame this as 'how many parallel task-review sessions do we need?' Both approaches are O(n log n) — the two-pointer solution is clever and compact, but the min-heap version maps more naturally to a real room-allocation system where rooms have identities. Mention that in production you'd use an actual priority queue library; the sorted-array stand-in is for whiteboard clarity.
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 Asana interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →