You are given two tables: Listens and Friendship.
The Listens table tracks when users listen to songs on specific days, while the Friendship table contains pairs of friends where user1_id < user2_id.
Write a solution to find similar friends - pairs of friends who listened to the same three or more different songs on the same day.
Return the result maintaining the original format where user1_id < user2_id.
Table Schema
| Column Name | Type | Description |
|---|---|---|
user_id
|
int | ID of the user who listened to the song |
song_id
|
int | ID of the song that was listened to |
day
|
date | Date when the song was listened to |
| Column Name | Type | Description |
|---|---|---|
user1_id
PK
|
int | ID of the first user in friendship pair |
user2_id
PK
|
int | ID of the second user in friendship pair |
Input & Output
| user_id | song_id | day |
|---|---|---|
| 1 | 10 | 2021-03-15 |
| 1 | 11 | 2021-03-15 |
| 1 | 12 | 2021-03-15 |
| 2 | 10 | 2021-03-15 |
| 2 | 11 | 2021-03-15 |
| 2 | 12 | 2021-03-15 |
| 3 | 10 | 2021-03-15 |
| 3 | 11 | 2021-03-15 |
| 1 | 10 | 2021-03-16 |
| 1 | 11 | 2021-03-16 |
| 2 | 10 | 2021-03-16 |
| 2 | 11 | 2021-03-16 |
| user1_id | user2_id |
|---|---|
| 1 | 2 |
| 1 | 3 |
| 2 | 3 |
| user1_id | user2_id |
|---|---|
| 1 | 2 |
Users 1 and 2 are friends and both listened to songs 10, 11, and 12 on 2021-03-15 (3 shared songs). Although they also shared songs on 2021-03-16, they only shared 2 songs that day. Users 1 and 3 are friends but only shared 2 songs on 2021-03-15, which is less than the required 3.
| user_id | song_id | day |
|---|---|---|
| 1 | 10 | 2021-03-15 |
| 1 | 11 | 2021-03-15 |
| 2 | 10 | 2021-03-15 |
| 2 | 12 | 2021-03-15 |
| user1_id | user2_id |
|---|---|
| 1 | 2 |
| user1_id | user2_id |
|---|
Users 1 and 2 are friends but only shared 1 song (song 10) on 2021-03-15, which is less than the required 3 shared songs. Therefore, no similar friends are found.
Constraints
-
1 ≤ user_id ≤ 10^9 -
1 ≤ song_id ≤ 10^9 -
dayis a valid date -
user1_id < user2_idin Friendship table