Skip to content

Commit 3825265

Browse files
authored
Create leetcodify-similar-friends.sql
1 parent f72f9c2 commit 3825265

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

MySQL/leetcodify-similar-friends.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Time: O(n * l), n is the number of users, l is the number of listens
2+
# Space: O(n * l)
3+
4+
SELECT DISTINCT a.user_id user1_id,
5+
b.user_id user2_id
6+
FROM friendship c
7+
INNER JOIN listens a ON c.user1_id = a.user_id
8+
INNER JOIN listens b ON c.user2_id = b.user_id AND a.day = b.day AND a.song_id = b.song_id
9+
GROUP BY c.user1_id,
10+
c.user2_id,
11+
a.day
12+
HAVING Count(DISTINCT a.song_id) >= 3
13+
ORDER BY NULL;

0 commit comments

Comments
 (0)