Skip to content

Commit 04a0829

Browse files
[N-0] add 603
1 parent 3c070b8 commit 04a0829

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ Your ideas/fixes/algorithms are more than welcome!
675675
|610|[Triangle Judgement](https://leetcode.com/problems/triangle-judgement/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_610.java) | | | Easy |
676676
|608|[Tree Node](https://leetcode.com/problems/tree-node/)|[Solution](../master/database/_608.sql) | | | Medium | Union
677677
|607|[Sales Person](https://leetcode.com/problems/sales-person/)|[Solution](../master/database/_607.sql) | | | Easy |
678+
|603|[Consecutive Available Seats](https://leetcode.com/problems/sales-person/)|[Solution](../master/database/_603.sql) | | | Easy |
678679
|602|[Friend Requests II: Who Has the Most Friends](https://leetcode.com/problems/friend-requests-ii-who-has-the-most-friends/)|[Solution](../master/database/_602.sql) | | | Medium |
679680
|601|[Human Traffic of Stadium](https://leetcode.com/problems/human-traffic-of-stadium/)|[Solution](../master/database/_601.sql) | | | Hard |
680681
|597|[Friend Requests I: Overall Acceptance Rate](https://leetcode.com/problems/friend-requests-i-overall-acceptance-rate/)|[Solution](../master/database/_597.sql) | | | Easy |

database/_603.sql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--603. Consecutive Available Seats
2+
--
3+
--Several friends at a cinema ticket office would like to reserve consecutive available seats.
4+
--Can you help to query all the consecutive available seats order by the seat_id using the following cinema table?
5+
--
6+
--| seat_id | free |
7+
--|---------|------|
8+
--| 1 | 1 |
9+
--| 2 | 0 |
10+
--| 3 | 1 |
11+
--| 4 | 1 |
12+
--| 5 | 1 |
13+
--Your query should return the following result for the sample case above.
14+
--| seat_id |
15+
--|---------|
16+
--| 3 |
17+
--| 4 |
18+
--| 5 |
19+
--Note:
20+
--The seat_id is an auto increment int, and free is bool ('1' means free, and '0' means occupied.).
21+
--Consecutive available seats are more than 2(inclusive) seats consecutively available.
22+
23+
select c.seat_id from cinema c where c.free = 1
24+
and
25+
(
26+
c.seat_id+1 in (select seat_id from cinema where free=1)
27+
or
28+
c.seat_id-1 in (select seat_id from cinema where free=1)
29+
)
30+
order by c.seat_id

0 commit comments

Comments
 (0)