Skip to the solution
MediumDSA5 min read

How do you find the minimum number of meeting rooms required?

381 views

The problem

Question presented to candidate: "Given a list of meetings as [start, end] pairs, write a Python function that returns the minimum number of conference rooms needed so that no two overlapping meetings share a room."

What a strong answer should cover:

  • The answer is the maximum number of meetings running at the same time.
  • Sort by start, keep a min-heap of end times; reuse the room on top when its end is <= the new start, otherwise open a room. O(n log n) time, O(n) space.
  • The sweep-line alternative: +1/โˆ’1 events sorted by time, ends before starts on ties.
  • Edge cases: back-to-back meetings share a room, identical meetings need separate rooms, empty input is 0.
  • Python details: heapq is a min-heap on a plain list (ends[0] is the smallest), heapq.heapreplace pops and pushes in one call, and sorted() on tuples orders ends before starts when you encode them as (time, -1) and (time, +1).

Clarifying questions expected:

  • Can a meeting ending at 10 share a room with one starting at 10?
  • Is the input already sorted?

Code / implementation expected: Yes โ€” a function min_meeting_rooms(meetings) -> int using heapq, in Python 3.

  • intervals
  • sorting
  • heap

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

5 min read ยท 11 sections

Python code

Edit the code and run it here. Each printed line with an expected value becomes a test.

PythonSort by start + min-heap of end times (7 schedules)
PythonSweep line trace + random cross-check of three methods

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 94 of 154 in DSA

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

All DSA questions
Up nextMedium

How do you solve the Gas Station problem?

Continue