Each row in RequestAccepted is an accepted friendship between requester_id and accepter_id (both person ids). Return the person with the most friends as id and their friend count num.
Input Table(s)
RequestAccepted
| Column | Type | Meaning |
|---|
| requester_id | INT, NOT NULL | Person who sent the friend request |
| accepter_id | INT, NOT NULL | Person who accepted it |
| accept_date | DATE, nullable | Day the request was accepted |
Key: (requester_id, accepter_id) is unique.
Output Contract
-
Exactly one row with columns
id
and
num
.
-
id
is the person with the most friends.
-
num
is that person's friend count: the number of rows in which they appear, as
requester_id
or as
accepter_id
.
-
The input guarantees a single winner, so the result has one row and needs no further ordering.
Example
RequestAccepted
| requester_id | accepter_id | accept_date |
|---|
| 1 | 2 | 2016-06-03 |
| 1 | 3 | 2016-06-08 |
| 2 | 3 | 2016-06-08 |
| 3 | 4 | 2016-06-09 |
Expected result:
Person 3 appears as accepter in rows (1, 3) and (2, 3) and as requester in row (3, 4), giving 3 friends total. Person 1 has 2 friends, person 2 has 2 friends, and person 4 has 1 friend. So person 3 has the most friends.
Constraints and Clarifications
-
At most 50,000 rows.
-
The answer is unique (no ties).
-
requester_id != accepter_id
for every row.
-
Each
(requester_id, accepter_id)
pair is unique, and each friendship is stored in one row only, so the number of rows a person appears in is their number of friends.
-
accept_date
can be NULL. It does not affect the count.