Skip to main content

76. Meeting Rooms II

mediumAsked at Salesforce

Find the minimum number of meeting rooms needed for a set of meetings with start/end times. Salesforce uses this in their Calendar app's room booking and resource allocation algorithms.

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

Source citations

Public interview reports confirming this problem appears in Salesforce loops.

  • Glassdoor (2026-Q1)Salesforce Calendar app uses this for room booking.
  • Blind (2025-12)Recurring on Salesforce L4/L5 onsites.

Problem

Given an array of meeting time 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. Chronological sweep with sorted starts and ends

Sort starts and ends separately. Walk starts; if next start < earliest end, add a room; else reuse (advance end pointer).

Time
O(n log n)
Space
O(n)
function minMeetingRooms(intervals) {
  const starts = intervals.map(x => x[0]).sort((a, b) => a - b);
  const ends = intervals.map(x => x[1]).sort((a, b) => a - b);
  let rooms = 0, endIdx = 0;
  for (let i = 0; i < starts.length; i++) {
    if (starts[i] < ends[endIdx]) rooms++;
    else endIdx++;
  }
  return rooms;
}

Tradeoff: Elegant. The chronological sweep avoids explicit heaps.

2. Min-heap of end times

Sort by start. For each meeting: if heap.top < start, pop (room frees up). Push end. Answer is max heap size.

Time
O(n log n)
Space
O(n)
// Pseudocode (real impl needs heap class):
function minMeetingRooms(intervals) {
  intervals.sort((a, b) => a[0] - b[0]);
  const heap = []; // min-heap of ends
  for (const [s, e] of intervals) {
    if (heap.length && heap[0] <= s) heap.shift();
    heap.push(e);
    heap.sort((a, b) => a - b); // proxy for heap
  }
  return heap.length;
}

Tradeoff: Min-heap explicitly tracks ongoing meetings. More intuitive but requires a heap implementation. Both approaches are O(n log n).

Salesforce-specific tips

Salesforce uses this directly in their Calendar app (room booking) and Activity-based capacity planning. They grade on whether you can articulate WHY the chronological sweep works — the key insight is that we only need to know how many starts have occurred without a matching end. Bonus signal: discuss the trade-off with the heap approach.

Common mistakes

  • Using start <= end instead of start < end — same-time end/start should reuse the room, not double-book.
  • Not sorting starts and ends separately — must be independent.
  • Implementing heap with sort — works but O(n^2 log n) instead of O(n log n).

Follow-up questions

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

  • Meeting Rooms (LC 252) — just decide if any room works.
  • Merge Intervals (LC 56).
  • Car Pooling (LC 1094) — same chronological-sweep pattern.

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 sort starts and ends separately?

Because the algorithm processes events chronologically across BOTH start and end times. Independent sorts make it O(n log n) without losing correctness.

Why < and not <=?

A meeting ending at time t allows another meeting to start at t — they don't conflict. So start < end means conflict; equality is OK.

Practice these live with InterviewChamp.AI

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

Practice these live with InterviewChamp.AI →