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:
heapqis a min-heap on a plain list (ends[0]is the smallest),heapq.heapreplacepops and pushes in one call, andsorted()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.