Compute the Minimum Number of Meeting Rooms
Walmart LabsSoftware Engineer · Technical ScreenLast updated
Determine the minimum number of meeting rooms required to accommodate a set of schedule intervals where intervals are half-open and meetings can start at the exact moment another ends.
Problem Statement
Given an array of meeting time intervals intervals where each interval is represented as [start, end], return the minimum number of conference rooms required to hold all meetings.
Intervals are half-open [start, end). This means that a meeting ending at time T and another meeting starting at time T do not overlap, and both can use the same room without conflict.
Your solution should not mutate the input array.
Function Signature
def min_meeting_rooms(intervals: list[list[int]]) -> int:
pass
Input and Output Format
- Input: A list of lists of integers, where each inner list contains two integers
[start, end]representing the start time and end time of a meeting. - Output: An integer representing the minimum number of meeting rooms needed.
Constraints
0 <= len(intervals) <= 10^5intervals[i].length == 20 <= start < end <= 10^9
Examples
Example 1
Input: intervals = [[0, 30], [5, 10], [15, 20]]
Output: 2
Explanation:
- Room 1 hosts: [0, 30]
- Room 2 hosts: [5, 10] and then [15, 20]
At most 2 meetings run concurrently.
Example 2
Input: intervals = [[7, 10], [2, 4]]
Output: 1
Explanation:
Since neither interval overlaps, a single room is sufficient.
Example 3
Input: intervals = [[1, 5], [5, 10]]
Output: 1
Explanation:
The first meeting ends at time 5, and the second meeting begins at time 5. Because intervals are half-open, they do not overlap.
Edge Cases to Consider
- Empty input:
intervals = []should return0. - Adjacent meetings sharing boundaries: e.g.,
[1, 3]and[3, 5]require only1room. - Completely nested intervals: e.g.,
[1, 10]and[2, 5]require2rooms. - Identical intervals: multiple meetings with identical start and end times must each receive their own room.
Hints
Hint 1
Consider modeling this problem around time points where room occupancy changes: start times increase required rooms, while end times decrease them.
Hint 2
If you separate and sort start times and end times independently, how does advancing through both lists help track current concurrent meetings?
Hint 3
When a meeting starts at the exact same time another ends, make sure you process the ending meeting first so that the room can be immediately reused.
Follow-up questions
- How does the time and space complexity of the two-pointer / line-sweep approach compare to using a min-heap to track active end times?
- How would you modify your algorithm if you also needed to return the actual schedule assignment (which meeting is held in which room)?
- If the time coordinates are bounded within a small integer range (e.g., minutes in a single day, 0 to 1440), could you achieve linear time complexity?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.