602. Friend Requests II: Who Has the Most Friends LeetCode Solution
In this guide, you will get 602. Friend Requests II: Who Has the Most Friends LeetCode Solution with the best time and space complexity. The solution to Friend Requests II: Who Has the Most Friends problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Friend Requests II: Who Has the Most Friends solution in C++
- Friend Requests II: Who Has the Most Friends solution in Java
- Friend Requests II: Who Has the Most Friends solution in Python
- Additional Resources

Problem Statement of Friend Requests II: Who Has the Most Friends
Table: RequestAccepted
+—————-+———+
| Column Name | Type |
+—————-+———+
| requester_id | int |
| accepter_id | int |
| accept_date | date |
+—————-+———+
(requester_id, accepter_id) is the primary key (combination of columns with unique values) for this table.
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.
Write a solution to find the people who have the most friends and the most friends number.
The test cases are generated so that only one person has the most friends.
The result format is in the following example.
Example not found
Constraints not found
Complexity Analysis
- Time Complexity: Google AdSense
- Space Complexity: Google Analytics
602. Friend Requests II: Who Has the Most Friends LeetCode Solution in C++
WITH
AllIds AS (
SELECT requester_id AS id FROM RequestAccepted
UNION ALL
SELECT accepter_id FROM RequestAccepted
)
SELECT
id,
COUNT(*) AS num
FROM AllIds
GROUP BY 1
ORDER BY 2 DESC
LIMIT 1;
/* code provided by PROGIEZ */
602. Friend Requests II: Who Has the Most Friends LeetCode Solution in Java
N/A
// code provided by PROGIEZ
602. Friend Requests II: Who Has the Most Friends LeetCode Solution in Python
N/A
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.