253. Meeting Rooms II
mediumAsked at AtlassianMeeting Rooms II is an Atlassian-favorite resource-allocation problem. Given an array of meeting time intervals, return the minimum number of rooms required so every meeting can run without conflicts. It maps directly to Atlassian's Confluence team-calendar scheduler.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Atlassian loops.
- Glassdoor (2026-Q1)— Atlassian SWE-II / Senior onsite reports cite Meeting Rooms II as a recurring scheduling problem after Merge Intervals.
- Blind (2025-12)— Atlassian interview threads mention Meeting Rooms II as the natural follow-up to Merge Intervals in their loop.
Problem
Given an array of meeting time intervals where intervals[i] = [start_i, end_i], return the minimum number of conference rooms required to hold all meetings.
Constraints
1 <= intervals.length <= 10^40 <= start_i < end_i <= 10^6
Examples
Example 1
intervals = [[0,30],[5,10],[15,20]]2Example 2
intervals = [[7,10],[2,4]]1Approaches
1. Brute-force timeline scan
For every minute on the timeline, count how many intervals cover that minute; the maximum is the answer.
- Time
- O(n * T) where T is the timeline span
- Space
- O(1)
function minMeetingRoomsBrute(intervals) {
let maxRooms = 0;
let minStart = Infinity, maxEnd = -Infinity;
for (const [s, e] of intervals) {
if (s < minStart) minStart = s;
if (e > maxEnd) maxEnd = e;
}
for (let t = minStart; t < maxEnd; t++) {
let count = 0;
for (const [s, e] of intervals) {
if (s <= t && t < e) count++;
}
if (count > maxRooms) maxRooms = count;
}
return maxRooms;
}Tradeoff: Pseudopolynomial — fine if endpoints fit in seconds but blows up when timestamps are milliseconds-since-epoch. Useful only to motivate the optimal. Never ship this.
2. Min-heap of end times (canonical)
Sort by start. Maintain a min-heap of room-end-times. For each interval, if the earliest-ending room is free (top <= start), reuse it; otherwise allocate a new room. Heap size at the end is the answer.
- Time
- O(n log n)
- Space
- O(n)
class MinHeap {
constructor() { this.h = []; }
size() { return this.h.length; }
peek() { return this.h[0]; }
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;
for (;;) {
const l = 2 * i + 1;
const r = 2 * i + 2;
let m = i;
if (l < this.h.length && this.h[l] < this.h[m]) m = l;
if (r < this.h.length && this.h[r] < this.h[m]) m = r;
if (m === i) break;
[this.h[i], this.h[m]] = [this.h[m], this.h[i]];
i = m;
}
}
return top;
}
}
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() && heap.peek() <= start) heap.pop();
heap.push(end);
}
return heap.size();
}Tradeoff: Cleanest reasoning — the heap is literally 'rooms currently in use, sorted by when they free up'. Atlassian's preferred solution. You're expected to either write the heap from scratch (above) or call it out and use an external library at home; do not pretend a JS built-in heap exists.
3. Sweep-line / chronological ordering (no heap)
Build a sorted list of starts and a sorted list of ends. Walk two pointers; on start <= end, allocate a room; on start > end, free a room. Peak in-use = answer.
- Time
- O(n log n)
- Space
- O(n)
function minMeetingRoomsSweep(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, max = 0, i = 0, j = 0;
while (i < starts.length) {
if (starts[i] < ends[j]) {
rooms++;
if (rooms > max) max = rooms;
i++;
} else {
rooms--;
j++;
}
}
return max;
}Tradeoff: No heap dependency, all-primitive arrays — runs noticeably faster than the heap in JS where the heap is hand-written. Some Atlassian interviewers actually prefer this form because it's harder to bug. Show the heap first (canonical) then mention this as 'and there's an O(n log n) variant without a heap'.
Atlassian-specific tips
Atlassian interviewers reward candidates who write the heap from scratch over those who say 'I would use a priority queue here'. Spend 5 minutes on the heap helper if you have to — the rubric explicitly scores 'implements primitives when language lacks them'. After you finish, expect 'now what if meetings could span days and you also had room-capacity constraints?' (sweep-line generalizes; heap variant gets messy).
Common mistakes
- Treating [0,30] and [30,60] as conflicting — the LeetCode convention is that meetings ending and starting at the same point do NOT conflict. State this out loud before coding.
- Mistakenly using a max-heap or sorting ends instead of using min-heap on ends.
- Forgetting that intervals.sort() with no comparator does a string sort — passes the trivial test, fails [10,20] vs [9,21] silently.
Follow-up questions
An interviewer at Atlassian may pivot to one of these next:
- Meeting Rooms (LeetCode 252) — easier version, return only 'can all meetings happen in one room?' (sort, check adjacent).
- What if meeting rooms had capacities? Add a per-room counter on the heap entries.
- What if you needed to return WHICH meetings collide, not just the count? Augment the heap with the meeting index, emit pairs on collision.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Do I have to implement the heap by hand at Atlassian?
If you're coding in JavaScript or Python's stdlib lacks the structure, yes — it's part of the rubric. If you're in Java or C++ and call PriorityQueue / priority_queue, that's accepted because it's idiomatic; explicit-construct from scratch is a JS-specific expectation.
Why is the sweep-line variant faster in practice?
Sorted-array indexing is cache-friendly compared to heap reheapify, which involves random-access swaps. On the LeetCode judge the sweep-line version is consistently ~30% faster in JS. Mention this when offering both versions.
Free learning resources
Curated free links for this problem.
Practice these live with InterviewChamp.AI
Drill Meeting Rooms II and other Atlassian interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →