Leetcode#253. Meeting Rooms II
Given an array of meeting time intervals
intervals[i] = [starti, endi], return the minimum number of conference rooms required.
Input: intervals = [[0,30],[5,10],[15,20]]
Input: intervals = [[7,10],[2,4]]
1 <= intervals.length <= 104
0 <= starti < endi <= 106
def minMeetingRooms(self, intervals: List[List[int]]) -> int:
# If there are no meetings, we don't need any rooms.
if not intervals:
return 0num_rooms = 0# Separate out the start and the end timings and sort them individually.
start_timings = sorted(i for i in intervals)
end_timings = sorted(i for i in intervals)
L = len(intervals)# The two pointers in the algorithm: e_ptr and s_ptr.
end_pointer = 0
start_pointer = 0# Until all the meetings have been processed
while start_pointer < L:
# If there is a meeting that has ended by the time the meeting at `start_pointer` starts
if start_timings[start_pointer] < end_timings[end_pointer]:
# Free up a room and increment the end_pointer.
num_rooms += 1
end_pointer += 1start_pointer += 1return num_rooms