AnalystPath

Mutual Friend Suggestions

SQLHardSenior levelMeta~15 min

Problem

**[Asked at Facebook/Meta]**

Facebook's "People You May Know" feature recommends friend pairs who are **not yet
friends** but share **2 or more mutual friends**.

Given a friendship graph (each pair stored once with `user_a < user_b`), find all
such recommendation-worthy pairs. Return `user_a`, `user_b`, and `mutual_count`,
ordered by mutual_count descending, then user_a ascending.

Tables

Example rows — the live problem includes the full dataset.

friendships
user_auser_b

Expected output

Your answer should return 3 rows with the columns user_a, user_b, mutual_count.

Starter code (SQL)

SELECT *
FROM friendships;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions