Pairs of Users Who Share at Least Three Messenger Group Chats
Last updated: November 29, 2026
Quick Overview
From a Messenger group membership table, find all unordered pairs of users who are both members of at least three of the same group chats, ignoring groups with more than 50 members.
Meta
November 29, 20260
0
0 solved
From a Messenger group membership table, find all unordered pairs of users who are both members of at least three of the same group chats, ignoring groups with more than 50 members.
Overlap of group memberships is a strong closeness signal for Meta's social graph features. This tests a self join on a membership table, producing unordered pairs once, deduping membership rows, and controlling the quadratic blow-up from large groups.
What the Interviewer Expects
- Dedupes membership rows before the self join
- Self joins on thread_id with a.user_id < b.user_id
- Filters out large groups before joining to control row explosion
- Groups by pair with HAVING COUNT(DISTINCT thread_id) >= 3
- Estimates the join size as the sum of n choose 2 over groups
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How many rows does the self join produce for a 5,000 member group?
- How would you weight overlap by group size instead of filtering?
- How would you compute this incrementally each day?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
thread_members(thread_id, user_id, joined_at, left_at). A user who leaves and rejoins has two rows, so I dedupe. I will count only current members (left_at is NULL), and only threads with 3 to 50 cu...
Approach
- Current, deduped membership per (thread, user).
- Keep threads whose member count is at most 50.
- Self join on thread with
a.user_id < b.user_id, which emits each unordered pair once per share...