-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathCinema Seat Allocation
More file actions
29 lines (29 loc) · 891 Bytes
/
Copy pathCinema Seat Allocation
File metadata and controls
29 lines (29 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
public:
int maxNumberOfFamilies(int n, vector<vector<int>>& reservedSeats) {
unordered_map<int, unordered_map<int, bool>> lookup;
for (const auto& seat : reservedSeats) {
if (2 <= seat[1] && seat[1] <= 5) {
lookup[seat[0]][0] = true;
}
if (4 <= seat[1] && seat[1] <= 7) {
lookup[seat[0]][1] = true;
}
if (6 <= seat[1] && seat[1] <= 9) {
lookup[seat[0]][2] = true;
}
}
int result = 2 * n;
for (auto& [_, reserved] : lookup) {
if (!reserved[0] && !reserved[2]) {
continue;
}
if (!reserved[0] || !reserved[1] || !reserved[2]) {
--result;
continue;
}
result -= 2;
}
return result;
}
};