Person with the most friends
MediumP3Coding
Table request_accepted:
| Column | Type |
|---|---|
| requester_id | int |
| accepter_id | int |
Each row is one accepted friend request, which makes the two people friends. A pair appears at most once, in one direction only. A person's friends can come from either column.
Find the person with the most friends. If several people tie, return all of them.
Output columns: id, num (number of friends).
Schema
CREATE TABLE request_accepted ( requester_id int NOT NULL, accepter_id int NOT NULL, PRIMARY KEY (requester_id, accepter_id) );
Example 1
- Input
- request_accepted: (1, 2), (1, 3), (2, 3), (3, 4)
- Output
- (3, 3)
- Why
- Person 3 is friends with 1, 2 and 4.
Constraints
- PostgreSQL dialect.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
PostgreSQL
Run checks the 3 visible tests, Submit all 5. ⌘Enter runs, ⌘⇧Enter submits.