Cinema Seat Allocation LeetCode solution in Python

1
class Solution(object):
2
def maxNumberOfFamilies(self, n, reservedSeats):
3
"""
4
:type n: int
5
:type reservedSeats: List[List[int]]
6
:rtype: int
7
"""
8
d = defaultdict(set)
9
for row, seat in reservedSeats:
10
d[row].add(seat)
11

12
def row(i):
13
a1 = not set((2, 3, 4, 5)).intersection(d[i])
14
a2 = not set((6, 7, 8, 9)).intersection(d[i])
15
if a1 and a2:
16
return 2
17
if a1 or a2:
18
return 1
19
return 1 if not set((4, 5, 6, 7)).intersection(d[i]) else 0
20

21
return sum((row(i) for i in d.keys())) + (n - len(d)) * 2

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0