Groups Joined by a User's Friends but Not by the User
Last updated: November 29, 2026
Quick Overview
For a Facebook Groups recommendation candidate list, return for each user the groups that at least two of their friends belong to and that the user has not joined, ranked by the number of distinct friends in the group.
Meta
November 29, 20260
0
0 solved
For a Facebook Groups recommendation candidate list, return for each user the groups that at least two of their friends belong to and that the user has not joined, ranked by the number of distinct friends in the group.
Candidate generation for Groups You Should Join starts from simple graph joins like this before any model scores them. The interviewer checks a friend-to-membership join, an anti join on the user's own memberships, deduping symmetric friendship storage, and controlling size.
What the Interviewer Expects
- Expands friendships to both directions exactly once
- Joins friends to group memberships
- Anti joins the user's own memberships
- Counts distinct friends per (user, group) and applies HAVING >= 2
- Limits candidates per user with a window rank
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 would you handle friends who are members of thousands of groups?
- How would you add a group size normalization?
- How would you exclude groups the user previously left or hid?
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
friendships(user_a, user_b) with each pair stored once in arbitrary order. group_members(group_id, user_id, left_at); only current members count. I want up to 50 candidates per user....
Approach
- Make a directed friend table with both directions using
UNIONof the two orientations (UNION dedupes accidental double storage). - Join to memberships of the friend.
- Anti join where the user ...