Skip to main content

253. Meeting Rooms II

mediumAsked at Airbnb

Find the minimum number of rooms needed for overlapping meetings — Airbnb applies this directly to host-support queues, determining how many concierge agents must be on-call during peak booking hours.

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 schedule all meetings without conflicts.

Constraints

  • 1 <= intervals.length <= 10^4
  • 0 <= start_i < end_i <= 10^6

Examples

Example 1

Input
intervals = [[0,30],[5,10],[15,20]]
Output
2

Explanation: Meeting [0,30] conflicts with both others, but [5,10] and [15,20] can share a second room sequentially.

Example 2

Input
intervals = [[7,10],[2,4]]
Output
1

Explanation: The meetings do not overlap, so one room suffices.

Approaches

1. Chronological events sort

Split every interval into a +1 start event and a -1 end event, sort all events by time, then sweep to track concurrent rooms.

Time
O(n log n)
Space
O(n)
function minMeetingRooms(intervals) {
  const events = [];
  for (const [s, e] of intervals) {
    events.push([s, 1], [e, -1]);
  }
  events.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
  let rooms = 0, maxRooms = 0;
  for (const [, type] of events) {
    rooms += type;
    maxRooms = Math.max(maxRooms, rooms);
  }
  return maxRooms;
}

Tradeoff:

2. Min-heap (priority queue)

Sort by start time; use a min-heap of end times. For each meeting, if the earliest-ending room is free, reuse it. Otherwise allocate a new room. Heap size = 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 = (i - 1) >> 1;
      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) {
      this.h[0] = last;
      let i = 0;
      while (true) {
        let s = i, 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]; }
  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() && heap.peek() <= start) {
      heap.pop();
    }
    heap.push(end);
  }
  return heap.size();
}

Tradeoff:

Airbnb-specific tips

Airbnb uses this in the context of customer-support scheduling: 'How many agents do we need on-call given these support-call windows?' The heap approach is the expected answer — be ready to walk through why you pop only when the room end time is <= the new meeting start (not strictly less-than). Boundary conditions matter here.

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

Practice these live with InterviewChamp.AI

Drill Meeting Rooms II and other Airbnb interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →