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
Data Manipulation (SQL/Python)
Data Scientist
Meta
November 29, 2026
Data Scientist
Onsite
Data Manipulation (SQL/Python)
Hard

0

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
self join
unordered pairs
HAVING
join explosion
graph features
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. 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 Problems
Sample 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
  1. Current, deduped membership per (thread, user).
  2. Keep threads whose member count is at most 50.
  3. Self join on thread with a.user_id < b.user_id, which emits each unordered pair once per share...

Submit Your Answer
Markdown supported