Skip to main content

253. Meeting Rooms II

mediumAsked at Twilio

Meeting Rooms II is Twilio's resource-scheduling probe: given a list of meeting time intervals, return the minimum number of rooms required. Twilio's voice-team interview reports frame this as 'minimum concurrent call legs' — the algorithmic shape is identical. The grading bar is the sort-and-sweep with min-heap (or two sorted arrays) for O(n log n).

By Alex Chen, Founder, InterviewChamp.AI · Last verified

Source citations

Public interview reports confirming this problem appears in Twilio loops.

  • Glassdoor (2026-Q1)Heavily-cited in Twilio voice-team and SDK-engineering on-site reports.
  • LeetCode Discuss (2025-12)Recurring in Twilio interview reports across multiple teams; sometimes framed as concurrent-call counting.

Problem

Given an array of meeting time intervals intervals where intervals[i] = [start_i, end_i], return the minimum number of conference rooms required.

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

Example 2

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

Approaches

1. Brute-force point sweep (rejected for the constraint set)

Find the max number of meetings overlapping any time point — scan every minute / second / event boundary.

Time
O(n * range)
Space
O(1)
function minMeetingRoomsBrute(intervals) {
  let max = 0, end = 0;
  for (const [_, e] of intervals) if (e > end) end = e;
  for (let t = 0; t < end; t++) {
    let count = 0;
    for (const [s, e] of intervals) if (s <= t && t < e) count++;
    if (count > max) max = count;
  }
  return max;
}

Tradeoff: O(n * 10^6) with a million time points — instant TLE. Conceptually right but only works for sparse coordinate domains.

2. Min-heap of end times (optimal)

Sort by start. Walk through; if a heap's smallest end-time is <= current start, pop it (room frees up). Push current end. Heap size at end is the answer.

Time
O(n log n)
Space
O(n)
// JS doesn't ship a heap; using a minimal one inline
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 > 0) {
      this.h[0] = last;
      let i = 0;
      const n = this.h.length;
      while (true) {
        const l = 2 * i + 1, r = 2 * i + 2;
        let s = i;
        if (l < n && this.h[l] < this.h[s]) s = l;
        if (r < n && 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) {
  if (intervals.length === 0) return 0;
  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: Sort dominates at O(n log n). Heap operations are also log n. The heap holds the end times of currently-occupied rooms; popping when peek <= start represents a room becoming free.

3. Two sorted arrays — chronological event sweep (cleaner alternative)

Sort starts and ends separately. Walk both pointers — every start consumes a room; every end frees one. Track max concurrent.

Time
O(n log n)
Space
O(n)
function minMeetingRoomsTwoArr(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, maxRooms = 0, i = 0, j = 0;
  while (i < starts.length) {
    if (starts[i] < ends[j]) {
      rooms++;
      i++;
      if (rooms > maxRooms) maxRooms = rooms;
    } else {
      rooms--;
      j++;
    }
  }
  return maxRooms;
}

Tradeoff: Same asymptotics, no heap needed. Often cleaner to write in interview because JS doesn't ship a heap. The 'starts[i] < ends[j]' (strict less-than) is correct because a meeting ending at time T and another starting at T can share a room.

Twilio-specific tips

Twilio's voice and SDK teams use this exact algorithm in production for concurrent-call-leg accounting and rate-limit reservoir sizing. Mention the domain relevance — interview reports show this lands well. The 'two sorted arrays' variant is the canonical no-heap answer; if you write the heap version, walk through what the heap is invariantly storing ('end times of currently-occupied rooms') before the code.

Common mistakes

  • Using `<=` instead of `<` in the start-vs-end compare — incorrectly forces a new room when a meeting ending at T meets one starting at T.
  • Sorting the intervals together by start AND end with a stable comparator — works but is harder to reason about than two separate sorted arrays.
  • Forgetting that rooms decreases on end-events and never goes negative if the intervals are valid.

Follow-up questions

An interviewer at Twilio may pivot to one of these next:

  • What if you needed to return the ASSIGNMENT (which interval used which room), not just the count? (Heap of (endTime, roomId) — pop gives the freed room, assign current to it.)
  • What if intervals arrived as a stream and you had to maintain max-concurrent online? (Sorted-multiset of end times + counter — log n per add/remove.)
  • How would you generalize to N-dimensional 'meetings' (start/end in multiple dimensions)? (Sweep-line per dimension or a segment tree.)

Solve it now

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

Output

Press Run or Cmd+Enter to execute

FAQ

Why does the two-sorted-arrays variant work?

Because we don't care WHICH interval is in WHICH room — only how many are concurrent at any time. Sorting starts and ends independently and stepping through both pointers reconstructs the chronological event sequence, and the max running count is the answer.

When does Twilio prefer one approach over the other?

Heap version when the interviewer wants to extend to 'return assignment' (heap's pop tells us which room freed up). Two-arrays version when it's pure count and code-cleanliness matters. Either is acceptable on the rubric.

Free learning resources

Curated free links for this problem.

Practice these live with InterviewChamp.AI

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

Practice these live with InterviewChamp.AI →