File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
603-consecutive-available-seats Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ PDF /
2
+ * .docx
3
+ Challenging Problems on LeetCode.txt
Original file line number Diff line number Diff line change
1
+ -- --Solution to LeetCode Database question 603: Consecutive Available Seats
Original file line number Diff line number Diff line change
1
+ ### 603. Consecutive Available Seats
2
+
3
+ Table: cinema
4
+
5
+ ``` markdown
6
+ +-------------+------+
7
+ | Column Name | Type |
8
+ | seat_id | int |
9
+ +-------------+------+
10
+ seat_id is an auto-increment primary key column for this table.
11
+ Each row of this table indicates whether the ith seat is free or not. 1 means free while 0 means occupied.
12
+ ```
13
+
14
+ Write an SQL query to report all the consecutive available seats in the cinema.
15
+
16
+ Return the result table ordered by ` seat_id ` in ascending order.
17
+
18
+ The test cases are generated so that more than two seats are consecutively available.
19
+
20
+ The query result format is in the following example.
21
+
22
+ ** Example 1:**
23
+
24
+ ``` markdown
25
+ Cinema table:
26
+ +---------+------+
27
+ | seat_id | free |
28
+ +---------+------+
29
+ | 1 | 1 |
30
+ | 2 | 0 |
31
+ | 3 | 1 |
32
+ | 4 | 1 |
33
+ | 5 | 1 |
34
+ +---------+------+
35
+
36
+ output:
37
+ +---------+
38
+ | seat_id |
39
+ +---------+
40
+ | 3 |
41
+ | 4 |
42
+ | 5 |
43
+ +---------+
44
+ ```
You can’t perform that action at this time.
0 commit comments