MediumArrayHeapSortingGreedyUpdated Sep 2026

253. Meeting Rooms II

Asked at Google, Meta, Amazon, Microsoft and 6 more

Difficulty

Medium

Time

O(n log n)

Space

O(n)

Pattern

Array

Companies

10

Problem

You are given a list of meeting time intervals. Each interval is a pair [start, end], meaning a meeting begins at start and ends at end.

Return the minimum number of conference rooms needed so that every meeting can happen. Two meetings can share one room only if they do not overlap in time. A meeting that ends at time t and another that starts at time t do not overlap, so they can use the same room.

In short: find the largest number of meetings that are happening at the same moment. That number is the answer.

How many meetings overlap at once?

intervals[0,30][5,10][15,20]012[0,30] and [5,10] overlap → 2 rooms busy at time 5intervals[0,30][5,10][15,20]012[5,10] ends before [15,20] starts, so those two canshare one room
At time 5 the meeting [0,30] and [5,10] are both running, so we need at least 2 rooms.

Constraints

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

Examples

Example 1
Inputintervals = [[0,30],[5,10],[15,20]]
Output2
WhyThe meeting [0,30] runs the whole time. It overlaps with [5,10], and it also overlaps with [15,20]. But [5,10] and [15,20] do not overlap each other, so one extra room is enough for both. That gives 2 rooms.
Example 2
Inputintervals = [[7,10],[2,4]]
Output1
WhyThe first meeting ends at 4, and the second starts at 7. They never overlap, so a single room can host both.

Asked At

10 companies

How to Think About It

1

Sort meetings by start time. Use a min-heap to track end times of ongoing meetings.

2

For each meeting, check if the earliest ending meeting finishes before this one starts. If so, reuse that room (pop from heap).

3

The heap size at any point is the number of rooms simultaneously in use. Track the maximum heap size.

4

Why it works: the heap always contains the end times of currently occupied rooms. If the earliest end time <= current start, that room is free.

5

Alternative: sweep line. Create events (+1 at start, -1 at end). Sort by time (end before start for ties). Track max concurrent.

6

Edge cases: no meetings (0 rooms), all meetings overlap (n rooms), no overlaps (1 room).

Optimal Approach

Step 1: Sort intervals by start time.
Step 2: Use a min-heap of end times.
Step 3: For each meeting [start, end]:
If heap[0] <= start, pop (room is free, reuse it).
Push end onto heap.
Step 4: Return len(heap) — the max rooms used.

Time: O(n log n) — sort + heap operations. Space: O(n).

Sort by start, keep end times in a min-heap

sort by start timeheap of end timesif heap top <= start: poppush end, track heap sizeThe heap size after each meeting is the number ofrooms in use right now.heap (end times)1030← topAfter [0,30] and [5,10]: two rooms busy, smallest endis 10heap (end times)2030← top[15,20] starts at 15, 10 <= 15 so we pop 10 and reusethat room, then push 20answer = max heap size = 2
The heap holds the end times of rooms still in use. If the smallest end time is <= the new start, that room is free.
ComplexityTime O(n log n)Space O(n)Sorting costs O(n log n), and each of the n meetings does one heap push (and maybe one pop), each O(log n).

What Trips People Up in Real Interviews

1

Confusing this with Meeting Rooms I. That problem asks if all meetings can attend (no overlaps). This one asks for the minimum number of rooms.

2

Sorting by end time instead of start time. You need to process meetings in start-time order to correctly count concurrent meetings.

3

Not reusing rooms. When a meeting ends before the next one starts, that room is free. Pop from the heap.

4

Forgetting to track the maximum heap size. The answer is the maximum number of simultaneous meetings, not the final heap size.

5

Using a max-heap instead of a min-heap. A max-heap tracks the latest ending meeting — useless for room reuse. A min-heap gives you the earliest ending meeting to check availability.

Solution Code

O(n log n) time
import heapq

def minMeetingRooms(intervals):
    if not intervals:
        return 0
    intervals.sort(key=lambda x: x[0])
    heap = []
    for start, end in intervals:
        if heap and heap[0] <= start:
            heapq.heappop(heap)
        heapq.heappush(heap, end)
    return len(heap)

Pro at DSA?

Test your skills with a real FAANG-style mock interview.

Start a Mock Interview →

Frequently Asked Questions

What is the Meeting Rooms II problem?

Given an array of meeting time intervals, find the minimum number of conference rooms required. This is a classic scheduling problem that tests heap and greedy skills.

How do you solve Meeting Rooms II?

The optimal approach runs in O(n log n) time and O(n) space. Scroll up to "Optimal Approach" for the step-by-step walkthrough, diagrams, and code in Python, C++ and Java.

What companies ask Meeting Rooms II?

Meeting Rooms II is asked at Google, Meta, Amazon, Microsoft, Apple, Netflix, Uber, Salesforce, TikTok, JPMorgan. It is a medium difficulty problem.

What are common mistakes on Meeting Rooms II?
  • Confusing this with Meeting Rooms I. That problem asks if all meetings can attend (no overlaps). This one asks for the minimum number of rooms.
  • Sorting by end time instead of start time. You need to process meetings in start-time order to correctly count concurrent meetings.
  • Not reusing rooms. When a meeting ends before the next one starts, that room is free. Pop from the heap.
  • Forgetting to track the maximum heap size. The answer is the maximum number of simultaneous meetings, not the final heap size.
  • Using a `max-heap` instead of a `min-heap`. A `max-heap` tracks the latest ending meeting — useless for room reuse. A `min-heap` gives you the earliest ending meeting to check availability.