cinema-seat-allocation-v2.py (1417B)
1 class Solution: 2 def maxNumberOfFamilies(self, n: int, reservedSeats: List[List[int]]) -> int: 3 4 reservedSeats.sort() 5 count = 0 6 seat_index = 0 7 8 for row_num in range(1, n + 1): 9 10 first_seats = True 11 second_seats = True 12 third_seats = True 13 14 if seat_index < len(reservedSeats): 15 current_reserved = reservedSeats[seat_index] 16 17 while seat_index < len(reservedSeats) and current_reserved[0] == row_num: 18 if current_reserved[1] >= 2 and current_reserved[1] <= 5: 19 first_seats = False 20 if current_reserved[1] >= 4 and current_reserved[1] <= 7: 21 second_seats = False 22 if current_reserved[1] >= 6 and current_reserved[1] <= 9: 23 third_seats = False 24 25 seat_index += 1 26 27 if seat_index < len(reservedSeats): 28 current_reserved = reservedSeats[seat_index] 29 30 31 if first_seats and second_seats: 32 second_seats = False 33 if second_seats and third_seats: 34 third_seats = False 35 36 if first_seats: count += 1 37 if second_seats: count += 1 38 if third_seats: count += 1 39 40 return count