Welcome to the Cinema Seat Allocation problem! Imagine you're working for a popular movie theater chain, and your job is to maximize the number of four-person groups that can be seated together.
Each cinema has n rows of seats, numbered from 1 to n. Every row contains exactly 10 seats labeled 1 through 10, with a layout like this:
[1][2][3] | [4][5][6][7] | [8][9][10]
Notice the aisles (|) that separate the seats into three sections. A four-person group needs four adjacent seats in the same row. The tricky part? There are three possible arrangements:
- Left section: seats [2,3,4,5] (crosses the left aisle)
- Middle section: seats [4,5,6,7] (entirely in the middle)
- Right section: seats [6,7,8,9] (crosses the right aisle)
Given an array reservedSeats where reservedSeats[i] = [row, seat] represents already booked seats, your task is to find the maximum number of four-person groups you can accommodate.
Goal: Return the maximum number of complete 4-person groups that can be seated.
Input & Output
Visualization
Time & Space Complexity
Where r is the number of reserved seats. We only process rows that have reservations, not all n rows
Hash map stores reserved seats grouped by row, maximum r entries total
Constraints
- 1 โค n โค 109
- 1 โค reservedSeats.length โค 4 * 104
- reservedSeats[i].length == 2
- 1 โค reservedSeats[i][0] โค n
- 1 โค reservedSeats[i][1] โค 10
- Each seat appears at most once in reservedSeats