« Back

Meeting Rooms II

LeetCode Premium

Given an array of meeting time intervals intervals where intervals[i] = [start_i, end_i], return the minimum number of conference rooms required.

Solution

A very straightforward problem as long as one remembers heapq.

Cleaned up code

Time spent: 3m | Runtime: 18.71% | Memory: 19.62%

import heapq

class Solution:
    def minMeetingRooms(self, intervals: List[List[int]]) -> int:
        intervals.sort()
        in_progress = []
        in_use = 0
        for start, end in intervals:
            while in_progress and in_progress[0] <= start:
                heapq.heappop(in_progress)
            heapq.heappush(in_progress, end)
            in_use = max(in_use, len(in_progress))
        return in_use