Coding interview problems โ€บ Intervals

๐Ÿ“… Intervals Medium

Meeting Rooms II (Minimum Rooms)

Meeting Rooms II explained: the minimum number of rooms (or railway platforms) via a +1/-1 sweep or a min-heap of end times, tested Python and a live visual.

Also searched as: minimum number of meeting rooms ยท minimum platforms required for a railway station ยท maximum overlapping intervals

๐Ÿ“…

Try it live Free

Merge Intervals & Meeting Rooms

Switch the lab to meeting rooms: +1 at every start, -1 at every end, and watch the counter's peak become the minimum number of rooms.

Also useful: Binary Heap & Priority Queue

Open the playground โ†’

The problem

Given meeting times [start, end], find the minimum number of rooms needed so every meeting can take place. A room freed at time 10 can host a meeting starting at 10. This is the same as the "minimum platforms at a railway station" question.

Input[[0, 30], [5, 10], [15, 20]]
Output2
Input[[7, 10], [2, 4]]
Output1

The key insight

The number of rooms needed is the largest number of meetings running at the same moment. Walk through time: every start adds one busy room, every end frees one. Sort all starts and all ends separately and sweep them in order; the peak of the running count is the answer.

Brute force first: Checking, for every meeting start, how many other meetings are running at that moment is O(nยฒ).

Step-by-step approach

  1. Make sorted lists of all start times and all end times.
  2. Walk through the starts with a pointer j into the ends.
  3. For each start, first release every room whose end time is <= this start (advance j, decrement the count).
  4. Then take a room for this meeting (increment the count) and update the peak.
  5. Return the peak.

Python solution

PYTHON 3tested
def min_meeting_rooms(intervals):
    starts = sorted(s for s, _ in intervals)
    ends = sorted(e for _, e in intervals)
    rooms = peak = j = 0
    for s in starts:
        while j < len(ends) and ends[j] <= s:   # free rooms that ended
            rooms -= 1
            j += 1
        rooms += 1                              # this meeting takes a room
        peak = max(peak, rooms)
    return peak

Complexity

TimeO(n log n)
SpaceO(n)

Two sorts of n numbers dominate; the sweep is linear because j only moves forward.

Common mistakes

Frequently asked questions

What is the time and space complexity of Meeting Rooms II?

O(n log n) time for sorting and O(n) space for the start and end arrays. The min-heap method has the same bounds.

How does the min-heap solution work?

Sort meetings by start and keep a min-heap of end times of rooms in use. For each meeting, if the smallest end time is at or before its start, pop it (reuse that room); then push this meeting's end. The heap size at the end is the answer.

Is this the same as the minimum platforms problem?

Yes. Trains arriving and departing are meetings starting and ending, and platforms are rooms. Check the problem's rule for a train arriving exactly when another departs, since some versions count that as needing a separate platform.

Preparing for placements?

Take the 2-minute readiness check to find your weak patterns, then follow the placement path from DSA core to system design.

All coding interview problems More Intervals Merge Intervals & Meeting Rooms lab Placement prep guides

Problem statements on this site are written in our own words. Problem names are the common names used across interview-prep communities; BitBootcamp is an independent learning platform and is not affiliated with LeetCode or any company that asks these questions.