Billboard Pairs Enclosing Land
Problem
A survey records billboard locations on a grid by their map coordinates.
Table: `Billboards`
```text
+---------+------+
| Column | Type |
+---------+------+
| board_id| int |
| east | int |
| north | int |
+---------+------+
board_id is the primary key. east and north are the grid coordinates of the billboard.
```
Two billboards can serve as the opposite corners of an axis-aligned rectangular plot only if their east coordinates differ AND their north coordinates differ. For every such pair report `b1` (the smaller board_id), `b2` (the larger board_id), and the `plot_area` enclosed, computed as the absolute east difference times the absolute north difference. Order the result by `plot_area` descending, then by `b1` ascending, then by `b2` ascending.
Tables
Example rows — the live problem includes the full dataset.
| board_id | east | north |
|---|---|---|
| 1 | 2 | 7 |
| 2 | 4 | 8 |
| 3 | 2 | 10 |
Expected output
Your answer should return 2 rows with the columns b1, b2, plot_area.
Starter code (SQL)
SELECT *
FROM Billboards;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