Skip to content

Commit 6ab4fd2

Browse files
committedApr 12, 2025
Add solution #1386
1 parent 610d669 commit 6ab4fd2

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,269 LeetCode solutions in JavaScript
1+
# 1,270 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1056,6 +1056,7 @@
10561056
1382|[Balance a Binary Search Tree](./solutions/1382-balance-a-binary-search-tree.js)|Medium|
10571057
1383|[Maximum Performance of a Team](./solutions/1383-maximum-performance-of-a-team.js)|Hard|
10581058
1385|[Find the Distance Value Between Two Arrays](./solutions/1385-find-the-distance-value-between-two-arrays.js)|Easy|
1059+
1386|[Cinema Seat Allocation](./solutions/1386-cinema-seat-allocation.js)|Medium|
10591060
1389|[Create Target Array in the Given Order](./solutions/1389-create-target-array-in-the-given-order.js)|Easy|
10601061
1400|[Construct K Palindrome Strings](./solutions/1400-construct-k-palindrome-strings.js)|Medium|
10611062
1402|[Reducing Dishes](./solutions/1402-reducing-dishes.js)|Hard|
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* 1386. Cinema Seat Allocation
3+
* https://leetcode.com/problems/cinema-seat-allocation/
4+
* Difficulty: Medium
5+
*
6+
* A cinema has n rows of seats, numbered from 1 to n and there are ten seats in each row, labelled
7+
* from 1 to 10 as shown in the figure above.
8+
*
9+
* Given the array reservedSeats containing the numbers of seats already reserved, for example,
10+
* reservedSeats[i] = [3,8] means the seat located in row 3 and labelled with 8 is already reserved.
11+
*
12+
* Return the maximum number of four-person groups you can assign on the cinema seats. A four-person
13+
* group occupies four adjacent seats in one single row. Seats across an aisle (such as [3,3] and
14+
* [3,4]) are not considered to be adjacent, but there is an exceptional case on which an aisle
15+
* split a four-person group, in that case, the aisle split a four-person group in the middle, which
16+
* means to have two people on each side.
17+
*/
18+
19+
/**
20+
* @param {number} n
21+
* @param {number[][]} reservedSeats
22+
* @return {number}
23+
*/
24+
var maxNumberOfFamilies = function(n, reservedSeats) {
25+
const rowReservations = new Map();
26+
27+
for (const [row, seat] of reservedSeats) {
28+
if (!rowReservations.has(row)) {
29+
rowReservations.set(row, new Set());
30+
}
31+
rowReservations.get(row).add(seat);
32+
}
33+
34+
let result = 2 * (n - rowReservations.size);
35+
36+
for (const seats of rowReservations.values()) {
37+
let canPlaceGroup = false;
38+
39+
if (!seats.has(2) && !seats.has(3) && !seats.has(4) && !seats.has(5)) {
40+
result++;
41+
canPlaceGroup = true;
42+
}
43+
if (!seats.has(6) && !seats.has(7) && !seats.has(8) && !seats.has(9)) {
44+
result++;
45+
canPlaceGroup = true;
46+
}
47+
if (!canPlaceGroup && !seats.has(4) && !seats.has(5) && !seats.has(6) && !seats.has(7)) {
48+
result++;
49+
}
50+
}
51+
52+
return result;
53+
};

0 commit comments

Comments
 (0)
Please sign in to comment.