1386. Cinema Seat Allocation - cocoder39/coco39_LC GitHub Wiki

1386. Cinema Seat Allocation

class Solution:
    def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int:
        graph = collections.defaultdict(int)
        for seat in reservedSeats:
            row, col = seat[0], seat[1]
            graph[row] |= (1 << col)
        
        total = 0
        for row in graph.keys():
            count = 0
            reserved = graph[row]
            if (reserved & 60) == 0: # 11 1100
                count += 1
            if (reserved & 960) == 0: # 11 1100 0000
                count += 1
            if (reserved & 240) == 0 and count == 0: # 1111 0000
                count = 1
            total += count
        return (n - len(graph)) * 2 + total