Adjacent Open Parking Spots
Problem
A parking lot has a single row of numbered spots.
```
ParkingSpot
+----------+---------+
| Column | Type |
+----------+---------+
| spot_no | int |
| is_open | boolean |
+----------+---------+
spot_no is the primary key; spots are numbered consecutively.
```
`is_open` is 1 if the spot is free and 0 if it is taken. A driver wants two side-by-side free spots.
Return the `spot_no` of every free spot that is **next to another free spot** (the spot immediately before it or immediately after it, by `spot_no`, is also free). Order the result by `spot_no`.
Tables
Example rows — the live problem includes the full dataset.
| spot_no | is_open |
|---|---|
| 1 | 1 |
| 2 | 0 |
| 3 | 1 |
Expected output
Your answer should return 3 rows with the columns spot_no.
Starter code (SQL)
SELECT *
FROM ParkingSpot;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock