Skip to content

Commit

Permalink
Create friend-requests-ii-who-has-the-most-friends.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Nov 8, 2017
1 parent 9b060e0 commit 8a7560c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions MySQL/friend-requests-ii-who-has-the-most-friends.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Time: O(nlogn)
# Space: O(n)

SELECT ids as id, COUNT(*) AS num
FROM
(
SELECT requester_id AS ids FROM request_accepted
UNION ALL
SELECT accepter_id FROM request_accepted
) AS tmp
GROUP BY ids
ORDER BY num DESC
LIMIT 1
;

0 comments on commit 8a7560c

Please sign in to comment.