Tap here to switch tabs
Problem
Submissions

Problem: Cinema Seat Allocation

med
30 min
Try to solve the Cinema Seat Allocation problem.

Statement

A cinema has n rows of seats, numbered from 11 to n, with 1010 seats in each row numbered from 11 to 1010.

You are given the integer n and a 22D integer array reservedSeats, where reservedSeats[i] = [row, col] indicates that the seat at row row and column col is already reserved.

A four person family requires four adjacent seats in the same row. Seats separated by aisles (between seats 33 and 44, and between seats 77 and 88) are not considered adjacent. Consequently, the only valid configurations for a four person family are:

  • Seats 22, 33, 44, and 55

  • Seats 44, 55, 66, and 77

  • Seats 66, 77, 88, and 99

Return the maximum number of four person families you can seat in the cinema.

Note: A single row can seat at most 22 families (specifically, one in seats 22, 33, 44, 55 and one in seats 66, 77, 88, 99).

Constraints:

  • 1≤1 \leq n ≤109\leq 10^9

  • 1≤1 \leq reservedSeats.length ≤min⁡(10⋅\leq \min(10 \cdot n,104), 10^4)

  • reservedSeats[i].length =2= 2

  • 1≤1 \leq reservedSeats[i][0] ≤\leq n

  • 1≤1 \leq reservedSeats[i][1] ≤10\leq 10

  • All reservedSeats[i] are distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Cinema Seat Allocation

med
30 min
Try to solve the Cinema Seat Allocation problem.

Statement

A cinema has n rows of seats, numbered from 11 to n, with 1010 seats in each row numbered from 11 to 1010.

You are given the integer n and a 22D integer array reservedSeats, where reservedSeats[i] = [row, col] indicates that the seat at row row and column col is already reserved.

A four person family requires four adjacent seats in the same row. Seats separated by aisles (between seats 33 and 44, and between seats 77 and 88) are not considered adjacent. Consequently, the only valid configurations for a four person family are:

  • Seats 22, 33, 44, and 55

  • Seats 44, 55, 66, and 77

  • Seats 66, 77, 88, and 99

Return the maximum number of four person families you can seat in the cinema.

Note: A single row can seat at most 22 families (specifically, one in seats 22, 33, 44, 55 and one in seats 66, 77, 88, 99).

Constraints:

  • 1≤1 \leq n ≤109\leq 10^9

  • 1≤1 \leq reservedSeats.length ≤min⁡(10⋅\leq \min(10 \cdot n,104), 10^4)

  • reservedSeats[i].length =2= 2

  • 1≤1 \leq reservedSeats[i][0] ≤\leq n

  • 1≤1 \leq reservedSeats[i][1] ≤10\leq 10

  • All reservedSeats[i] are distinct.