meeting rooms ii

🏠
 1 from heapq import heappush as hpush
 2 from heapq import heappop as hpop
 3 from collections import namedtuple
 4 
 5 Interval = namedtuple("Interval", "start end")
 6 
 7 
 8 class Solution:
 9     def minMeetingRooms(self, iv):
10         if iv:
11             iv = sorted([Interval(*v) for v in iv], key=lambda x: x.start)
12             f = [iv[0].end]
13             for i in iv[1:]:
14                 if f[0] <= i.end:
15                     hpop(f)
16                 hpush(f, i.end)
17             return len(f)
18 
19 
20 print(Solution().minMeetingRooms([[0, 30], [5, 10], [15, 25], [20, 30]]))