Loading problem...
A music discovery platform wants to suggest new social connections from shared listening behavior.
Table: Listens
Table: Friendship
Recommendation policy: Recommend user x to user y if:
Important output behavior:
Output requirements:
Supported submission environments:
Listens:
| user_id | song_id | day |
|---------|---------|------------|
| 1 | 10 | 2024-03-01 |
| 1 | 11 | 2024-03-01 |
| 1 | 12 | 2024-03-01 |
| 2 | 10 | 2024-03-01 |
| 2 | 11 | 2024-03-01 |
| 2 | 12 | 2024-03-01 |
| 3 | 10 | 2024-03-01 |
| 3 | 11 | 2024-03-01 |
| 3 | 12 | 2024-03-01 |
| 4 | 10 | 2024-03-01 |
| 4 | 11 | 2024-03-01 |
| 4 | 13 | 2024-03-01 |
Friendship:
| user1_id | user2_id |
|----------|----------|
| 1 | 2 |[
{"user_id":1,"recommended_id":3},
{"user_id":2,"recommended_id":3},
{"user_id":3,"recommended_id":1},
{"user_id":3,"recommended_id":2}
]Users (1,3) and (2,3) each share 3 songs on the same day and are not friends. Pair (1,2) is excluded because they are already friends.
Listens:
| user_id | song_id | day |
|---------|---------|------------|
| 1 | 20 | 2024-05-10 |
| 1 | 20 | 2024-05-10 |
| 1 | 21 | 2024-05-10 |
| 1 | 22 | 2024-05-10 |
| 2 | 20 | 2024-05-10 |
| 2 | 20 | 2024-05-10 |
| 2 | 21 | 2024-05-10 |
| 3 | 20 | 2024-05-10 |
| 3 | 21 | 2024-05-10 |
| 3 | 22 | 2024-05-10 |
Friendship:
| user1_id | user2_id |
|----------|----------|
| (no rows) |[
{"user_id":1,"recommended_id":3},
{"user_id":3,"recommended_id":1}
]Duplicate listen rows do not increase distinct shared-song count. Users 1 and 3 share {20,21,22}; pairs involving user 2 share only two distinct songs.
Listens:
| user_id | song_id | day |
|---------|---------|------------|
| 7 | 31 | 2024-07-01 |
| 7 | 32 | 2024-07-01 |
| 7 | 33 | 2024-07-01 |
| 8 | 31 | 2024-07-01 |
| 8 | 32 | 2024-07-01 |
| 8 | 33 | 2024-07-01 |
| 7 | 40 | 2024-07-02 |
| 7 | 41 | 2024-07-02 |
| 7 | 42 | 2024-07-02 |
| 9 | 40 | 2024-07-02 |
| 9 | 41 | 2024-07-02 |
| 9 | 42 | 2024-07-02 |
Friendship:
| user1_id | user2_id |
|----------|----------|
| 7 | 8 |[
{"user_id":7,"recommended_id":9},
{"user_id":9,"recommended_id":7}
]Users 7 and 8 qualify by listening overlap but are filtered out because they are already friends. Users 7 and 9 qualify and are not friends, so both directions are returned.
Constraints