Leetcode 1487 Solution

This article provides solution to leetcode question 1487 (cinema-seat-allocation)

https://leetcode.com/problems/cinema-seat-allocation

Solution

class Solution: def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int: seats = {}
for x, y in reservedSeats: if x - 1 not in seats: seats[x - 1] = 0 seats[x - 1] |= 1 << (y - 1)
ans = (n - len(seats)) * 2 for i, mask in seats.items(): left = not bool(0b0111100000 & mask) right = not bool(0b0000011110 & mask) mid = not left and not right and not bool(0b0001111000 & mask)
ans += left + right + mid
return ans