Meeting rooms II#
Description#
- Given an array of meeting time intervals consisting of start and end times
[[s1,e1],[s2,e2],...] (si < ei), find
the minimum number of conference rooms required.
- i.e Find the maximum number of overlapped intervals
Example#
1Input: [[0, 30],[5, 10],[15, 20]],
2Output: 2
Python Solution#
1import heapq
2import operator
3
4
5class Interval:
6 def __init__(self, s=0, e=0):
7 self.start = s
8 self.end = e
9
10
11class Solution(object):
12 def minMeetingRooms(self, intervals):
13 """
14 :type intervals: list[Interval]
15 :rtype: int
16 """
17 maxa = 0
18
19 intervals.sort(key=operator.attrgetter("start"))
20 h_end = []
21 for itvl in intervals:
22 heapq.heappush(h_end, itvl.end)
23 while h_end and h_end[0] <= itvl.start:
24 heapq.heappop(h_end)
25
26 maxa = max(maxa, len(h_end))
27
28 return maxa