Skip to content

Commit 18491f7

Browse files
authored
Create find-the-missing-ids.sql
1 parent 3762f09 commit 18491f7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

MySQL/find-the-missing-ids.sql

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n^2)
2+
# Space: O(n)
3+
4+
WITH RECURSIVE Seq AS
5+
(SELECT 1 AS continued_id
6+
UNION ALL SELECT continued_id + 1
7+
FROM Seq
8+
WHERE continued_id <
9+
(SELECT MAX(customer_id)
10+
FROM Customers) )
11+
12+
SELECT continued_id AS ids
13+
FROM Seq s
14+
WHERE NOT EXISTS
15+
(SELECT customer_id
16+
FROM Customers c
17+
WHERE c.customer_id = s.continued_id);
18+

0 commit comments

Comments
 (0)