Find the Unique Person with the Most Distinct Friends

Quick Overview

Find the person with the largest number of distinct friends in accepted friend requests.

Find the Unique Person with the Most Distinct Friends

Company: Amazon

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

### Problem Report id and num for the person with the most friends represented by RequestAccepted. An accepted friendship connects requester and accepter in both directions. Each request connects two different people. Count each friend once, including when both request directions appear. The source guarantees one unique winner. ### Tables Table: `RequestAccepted` ```text +----------------+---------+ | 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. ``` ### Example ```text RequestAccepted (requester_id,accepter_id,accept_date): (1,3,2021-01-01), (2,3,2021-01-02), (3,4,2021-01-03), (1,2,2021-01-04) Output (id,num): (3,3) ``` ### Optional follow-up If several people tie for the largest friend count, report all of them and that maximum count. ### What a Strong Answer Covers - Treat accepted friendships as connections in both directions. - Count distinct friends and return the person with the uniquely highest count. ### Follow-up Questions - How would you return every person tied for the highest count? - How would you include people who have no accepted friendships?

Overview: Find the person with the largest number of distinct friends in accepted friend requests.

Amazon logo
Amazon
mediumSoftware EngineerOtherData Manipulation (SQL/Python)
0
0

Problem

Report id and num for the person with the most friends represented by RequestAccepted. An accepted friendship connects requester and accepter in both directions. Each request connects two different people. Count each friend once, including when both request directions appear. The source guarantees one unique winner.

Tables

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.

Example

RequestAccepted (requester_id,accepter_id,accept_date): (1,3,2021-01-01), (2,3,2021-01-02), (3,4,2021-01-03), (1,2,2021-01-04)
Output (id,num): (3,3)

Optional follow-up

If several people tie for the largest friend count, report all of them and that maximum count.

What a Strong Answer Covers Guidance

  • Treat accepted friendships as connections in both directions.
  • Count distinct friends and return the person with the uniquely highest count.

Follow-up Questions Guidance

  • How would you return every person tied for the highest count?
  • How would you include people who have no accepted friendships?