You are given a table Relations that represents follower relationships between users.
Task: Find all pairs of users that have the maximum number of common followers.
- A common follower is someone who follows both users in a pair
- Return pairs
(user1_id, user2_id)whereuser1_id < user2_id - Only return pairs with the maximum count of common followers
For example, if the maximum number of common followers between any two users is 3, return all pairs that have exactly 3 common followers.
Table Schema
| Column Name | Type | Description |
|---|---|---|
user_id
PK
|
int | ID of the user being followed |
follower_id
PK
|
int | ID of the user who is following |
Input & Output
| user_id | follower_id |
|---|---|
| 1 | 3 |
| 2 | 3 |
| 7 | 3 |
| 1 | 4 |
| 2 | 4 |
| 7 | 4 |
| 1 | 5 |
| 6 | 5 |
| user1_id | user2_id |
|---|---|
| 1 | 2 |
| 1 | 7 |
| 2 | 7 |
Users 1, 2, and 7 all have followers 3 and 4 in common. Each pair (1,2), (1,7), and (2,7) has 2 common followers, which is the maximum. User 6 only shares follower 5 with user 1, giving them 1 common follower, which is less than the maximum.
| user_id | follower_id |
|---|---|
| 1 | 3 |
| 2 | 3 |
| 1 | 4 |
| 2 | 4 |
| 1 | 5 |
| 2 | 5 |
| 6 | 7 |
| user1_id | user2_id |
|---|---|
| 1 | 2 |
Users 1 and 2 have 3 common followers (3, 4, 5), which is the maximum. User 6 has no common followers with any other user, so only pair (1,2) is returned.
Constraints
-
1 ≤ user_id ≤ 1000 -
1 ≤ follower_id ≤ 1000 -
user_id ≠ follower_id(users cannot follow themselves)