Skip to content

Commit 62345d5

Browse files
committed
Create 602. Friend Requests II.sql
1 parent 574fe8b commit 62345d5

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
602. Friend Requests II: Who Has the Most Friends
2+
Solved
3+
Medium
4+
Topics
5+
Companies
6+
Hint
7+
SQL Schema
8+
Pandas Schema
9+
Table: RequestAccepted
10+
11+
+----------------+---------+
12+
| Column Name | Type |
13+
+----------------+---------+
14+
| requester_id | int |
15+
| accepter_id | int |
16+
| accept_date | date |
17+
+----------------+---------+
18+
(requester_id, accepter_id) is the primary key (combination of columns with unique values) for this table.
19+
This table contains the ID of the user who sent the request, the ID of the user who received the request, and the date when the request was accepted.
20+
21+
22+
Write a solution to find the people who have the most friends and the most friends number.
23+
24+
The test cases are generated so that only one person has the most friends.
25+
26+
The result format is in the following example.
27+
28+
29+
30+
Example 1:
31+
32+
Input:
33+
RequestAccepted table:
34+
+--------------+-------------+-------------+
35+
| requester_id | accepter_id | accept_date |
36+
+--------------+-------------+-------------+
37+
| 1 | 2 | 2016/06/03 |
38+
| 1 | 3 | 2016/06/08 |
39+
| 2 | 3 | 2016/06/08 |
40+
| 3 | 4 | 2016/06/09 |
41+
+--------------+-------------+-------------+
42+
Output:
43+
+----+-----+
44+
| id | num |
45+
+----+-----+
46+
| 3 | 3 |
47+
+----+-----+
48+
Explanation:
49+
The person with id 3 is a friend of people 1, 2, and 4, so he has three friends in total, which is the most number than any others.
50+
51+
52+
Follow up: In the real world, multiple people could have the same most number of friends. Could you find all these people in this case?
53+
54+
55+

0 commit comments

Comments
 (0)