Last updated on March 10th, 2025 at 11:07 pm
Here, we see the Consecutive Available Seats LeetCode Solution. This Leetcode problem is solved using MySQL and Pandas.
List of all LeetCode Solution
Level of Question
Easy

Consecutive Available Seats LeetCode Solution
Table of Contents
1. Problem Statement
Several friends at a cinema ticket office would like to reserve consecutive available seats.
Write a query for all the consecutive available seats ordered by the seat_id using the following cinema table.
The result format is in the following example.
Example 1:
Input:
seat_id |
3 |
4 |
5 |
Output:
seat_id | free |
1 | 1 |
2 | 0 |
3 | 1 |
4 | 1 |
5 | 1 |
Explanation:
The seat_id is an auto increment int, and free is bool (‘1’ means free, and ‘0 means occupied.).
Consecutive available seats are more than 2(inclusive) seats consecutively available.
2. Code Implementation in Different Languages
2.1 Consecutive Available Seats MySQL
select distinct c1.seat_id from cinema as c1 join cinema as c2 join cinema as c3 on c1.seat_id = c2.seat_id + 1 || c1.seat_id = c3.seat_id - 1 where c1.free = 1 and c2.free = 1 and c3.free = 1;