Cinema Seat Allocation LeetCode solution in Python
1class Solution(object):2def maxNumberOfFamilies(self, n, reservedSeats):3"""4:type n: int5:type reservedSeats: List[List[int]]6:rtype: int7"""8d = defaultdict(set)9for row, seat in reservedSeats:10d[row].add(seat)1112def row(i):13a1 = not set((2, 3, 4, 5)).intersection(d[i])14a2 = not set((6, 7, 8, 9)).intersection(d[i])15if a1 and a2:16return 217if a1 or a2:18return 119return 1 if not set((4, 5, 6, 7)).intersection(d[i]) else 02021return sum((row(i) for i in d.keys())) + (n - len(d)) * 2