cinema-seat-allocation-v3.py (1214B)
1 class Solution: 2 3 def start_from_seat(self, num): 4 to_remove = [] 5 if num >= 2 and num <= 5: 6 to_remove.append(2) 7 if num >= 4 and num <= 7: 8 to_remove.append(4) 9 if num >= 6 and num <= 9: 10 to_remove.append(6) 11 return to_remove 12 13 def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int: 14 15 valid = set() 16 17 occupied_rows = set() 18 19 for seat in reservedSeats: 20 occupied_rows.add(seat[0]) 21 22 23 24 for y in range(1,n+1): 25 if y not in occupied_rows: 26 continue 27 28 valid.add(str([y,2])) 29 valid.add(str([y,4])) 30 valid.add(str([y,6])) 31 32 for seat in reservedSeats: 33 to_remove = self.start_from_seat(seat[1]) 34 for start in to_remove: 35 valid.discard(str([seat[0],start])) 36 37 for y in range(1,n+1): 38 if str([y,2]) in valid and str([y,4]) in valid: 39 valid.discard(str([y,4])) 40 if str([y,4]) in valid and str([y,6]) in valid: 41 valid.discard(str([y,6])) 42 43 return len(valid) + ((n - len(occupied_rows)) * 2)