18. Meeting Rooms II
mediumAsked at BookingFind the minimum number of rooms to host all meetings — Booking uses the identical heap strategy to figure out how many concurrent reservations a property can handle before overbooking.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Problem
Given an array of meeting time intervals intervals[i] = [start_i, end_i], return the minimum number of conference rooms required to schedule all meetings without conflict.
Constraints
1 <= intervals.length <= 10^40 <= start_i < end_i <= 10^6
Examples
Example 1
intervals = [[0,30],[5,10],[15,20]]2Explanation: Rooms needed at time 5: [0,30] and [5,10] overlap, requiring 2 rooms.
Example 2
intervals = [[7,10],[2,4]]1Approaches
1. Brute force simulation
Track all open intervals at each start time by checking overlap with all others.
- Time
- O(n^2)
- Space
- O(n)
function minMeetingRooms(intervals) {
let maxRooms = 0;
for (let i = 0; i < intervals.length; i++) {
let rooms = 1;
for (let j = 0; j < intervals.length; j++) {
if (j !== i && intervals[j][0] < intervals[i][1] && intervals[i][0] < intervals[j][1]) {
rooms++;
}
}
maxRooms = Math.max(maxRooms, rooms);
}
return maxRooms;
}Tradeoff:
2. Min-heap on end times
Sort by start; use a min-heap of end times. For each meeting, if it starts after the earliest ending meeting, reuse that room; otherwise allocate a new one.
- Time
- O(n log n)
- Space
- O(n)
function minMeetingRooms(intervals) {
if (!intervals.length) return 0;
intervals.sort((a, b) => a[0] - b[0]);
// Min-heap simulated with sorted array (acceptable for interview)
const heap = [];
function heapPush(val) {
heap.push(val);
heap.sort((a, b) => a - b);
}
heapPush(intervals[0][1]);
for (let i = 1; i < intervals.length; i++) {
if (intervals[i][0] >= heap[0]) {
heap.shift(); // reuse earliest-ending room
}
heapPush(intervals[i][1]);
}
return heap.length;
}Tradeoff:
Booking-specific tips
Booking interviewers want to see you articulate WHY you track end times, not start times — it directly maps to 'when does a room become free?' They value clean heap reasoning over clever one-liners.
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 Booking interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →