Cinema Seat Allocation
Updated
Problem statement
A cinema has n rows of seats, numbered from 1 to n. Every row has ten seats, numbered from 1 to 10 from left to right. Two aisles run through every row: one between seats 3 and 4, and one between seats 7 and 8.
Some seats are already reserved. reservedSeats[i] = [row, seat] means that seat number seat in row row is taken.
A group of four people wants four free seats next to each other in one row. Two seats on opposite sides of an aisle do not count as next to each other, with one exception: a group may sit across an aisle when the aisle splits it in the middle, two people on each side.
Return the largest number of four-person groups that can be seated at the same time. No two groups can share a seat.
Function
maxNumberOfFamilies(n: int, reservedSeats: int[][]) → intExamples
Example 1
n = 3reservedSeats = [[1,4],[1,9],[2,3],[2,8],[3,1],[3,10]]return = 3In row 1, seats 4 and 9 are taken. Every four seats a group could use in that row include seat 4 or seat 9, so row 1 holds no group.
In row 2, seats 3 and 8 are taken. Seats 4 to 7 are free and lie between the two aisles, so one group sits there.
In row 3, only seats 1 and 10 are taken. One group takes seats 2 to 5, split two and two by the aisle between seats 3 and 4, and another group takes seats 6 to 9, split two and two by the aisle between seats 7 and 8.
That makes 0 + 1 + 2 = 3 groups.
Example 2
n = 4reservedSeats = [[2,5],[4,7]]return = 6Rows 1 and 3 have no reserved seat, so each holds two groups, one in seats 2 to 5 and one in seats 6 to 9.
In row 2, seat 5 is taken, so the only group that fits uses seats 6 to 9. In row 4, seat 7 is taken, so the only group that fits uses seats 2 to 5.
That makes 2 + 1 + 2 + 1 = 6 groups.
Example 3
n = 1000000000reservedSeats = [[1,5]]return = 1999999999Row 1 loses seat 5, so it holds one group, in seats 6 to 9. The other 999999999 rows have no reserved seat and hold two groups each, so the answer is 2 * 999999999 + 1 = 1999999999.
Constraints
1 <= n <= 1091 <= reservedSeats.length <= min(10 * n, 104)reservedSeats[i].length == 21 <= reservedSeats[i][0] <= n1 <= reservedSeats[i][1] <= 10- No seat appears twice in
reservedSeats.
More Zillow Phone Screen questions
- Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
- Time Based Key-Value StorePHONE SCREEN · Seen Feb 2024
- Filter Formatted Records by CriteriaPHONE SCREEN · Seen Sep 2023
- Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
- Jump GamePHONE SCREEN · Seen Dec 2022
- Reversible Run-Length EncodingPHONE SCREEN · Seen Nov 2022
- Spiral MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
- Two Sum: All PairsPHONE SCREEN · Seen Nov 2022
- Employee Free TimePHONE SCREEN · Seen Oct 2022
- First Unique Character in a StringPHONE SCREEN · Seen Oct 2022
Similar questions at other companies
- Task Scheduler with CooldownTeradata · PHONE SCREEN
- Find the Original Array From a Doubled ArrayGoogle · PHONE SCREENGoogle interview questions
- Future-Aware Cache EvictionBenchling · PHONE SCREENBenchling interview questions
- Task Scheduler with CooldownSambaNova Systems · PHONE SCREEN · ONSITE INTERVIEWSambaNova Systems interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Minimum Distinct Prefix CostChubb · OAChubb interview questions
- Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
- Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
- Nickname-Constrained GroupingZoox · ONSITE INTERVIEW
- 🐘 Keep Them Apart 🦙QRT · OA