Class Solution
java.lang.Object
g1301_1400.s1386_cinema_seat_allocation.Solution
1386 - Cinema Seat Allocation.<p>Medium</p>
<p><img src="https://assets.leetcode.com/uploads/2020/02/14/cinema_seats_1.png" alt="" /></p>
<p>A cinema has <code>n</code> rows of seats, numbered from 1 to <code>n</code> and there are ten seats in each row, labelled from 1 to 10 as shown in the figure above.</p>
<p>Given the array <code>reservedSeats</code> containing the numbers of seats already reserved, for example, <code>reservedSeats[i] = [3,8]</code> means the seat located in row <strong>3</strong> and labelled with <strong>8</strong> is already reserved.</p>
<p><em>Return the maximum number of four-person groups you can assign on the cinema seats.</em> A four-person group occupies four adjacent seats <strong>in one single row</strong>. Seats across an aisle (such as [3,3] and [3,4]) are not considered to be adjacent, but there is an exceptional case on which an aisle split a four-person group, in that case, the aisle split a four-person group in the middle, which means to have two people on each side.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/02/14/cinema_seats_3.png" alt="" /></p>
<p><strong>Input:</strong> n = 3, reservedSeats = [[1,2],[1,3],[1,8],[2,6],[3,1],[3,10]]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> The figure above shows the optimal allocation for four groups, where seats mark with blue are already reserved and contiguous seats mark with orange are for one group.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> n = 2, reservedSeats = [[2,1],[1,8],[2,6]]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> n = 4, reservedSeats = [[4,3],[1,4],[4,6],[1,7]]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n <= 10^9</code></li>
<li><code>1 <= reservedSeats.length <= min(10*n, 10^4)</code></li>
<li><code>reservedSeats[i].length == 2</code></li>
<li><code>1 <= reservedSeats[i][0] <= n</code></li>
<li><code>1 <= reservedSeats[i][1] <= 10</code></li>
<li>All <code>reservedSeats[i]</code> are distinct.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxNumberOfFamilies
public int maxNumberOfFamilies(int n, int[][] reservedSeats)
-