Skip to content

Commit 06c29a5

Browse files
authoredMay 31, 2020
Create rectangles-area.sql
1 parent 38778eb commit 06c29a5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
 

‎MySQL/rectangles-area.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Time: O(n^2)
2+
# Space: O(n^2)
3+
4+
SELECT *
5+
FROM
6+
(SELECT a.id AS P1,
7+
b.id AS P2,
8+
abs(a.x_value - b.x_value) * abs(a.y_value - b.y_value) AS area
9+
FROM Points a
10+
INNER JOIN Points b ON a.id < b.id
11+
ORDER BY area DESC, P1, P2) r
12+
WHERE area > 0;

0 commit comments

Comments
 (0)
Please sign in to comment.