2
public int maxNumberOfFamilies(int n, int[][] reservedSeats) {3
Map<Integer, int[]> seats = new HashMap<>();4
int availableSlots = 2 * n; // max available slots since each empty row could fit at max 2 slots6
for (int[] seat : reservedSeats) {9
int[] slots = seats.getOrDefault(row, new int[3]);11
if (col >= 2 && col <= 5) { // left slot14
if (col >= 4 && col <= 7) { // middle slot17
if (col >= 6 && col <= 9) { // right slot21
seats.put(seat[0], slots);24
for (int[] slots : seats.values()) {25
int taken = slots[0] + slots[2];27
if (taken == 2) { // both slots at either ends are taken28
if (slots[1] == 0) { // check if middle slot not taken29
availableSlots--; // reduce availableslots by 1 since middle slot is available31
availableSlots -= 2; // entire row not available - reduce by 233
} else if (taken == 1) { // one of the slots at either ends are taken34
availableSlots--; // reduce by 1 since either side of the slots not available36
continue; // entire row is available - no need to reduce the available slots40
return availableSlots;