Leetcode 253

Y Tech
Aug 9, 2023

Coding question asked in Meta, Google, and Amazon interviews.

'''
intervals = [[0,30],[5,10],[15,20]]
heapq: heapq sorted base on the end time, so that we can remove the finished meetings before adding a new meeting.
'''
from heapq import heappop, heappush
class Solution:
def minMeetingRooms(self, intervals: List[List[int]]) -> int:
res = 0
q = []
intervals.sort(key=lambda x: x[0])

for start, end in intervals:
while q and start >= q[0]:
heappop(q)
heappush(q, end)
res = max(res, len(q))
return res

--

--