Friend Requests Sent to People Who Are Already Friends

Last updated: November 29, 2026

Quick Overview

Facebook stores friendships once per pair in either column order, and friend requests as directed events. Find the share of yesterday's friend requests that were sent to someone the sender was already friends with, a sign of a client bug.

Meta
Data Manipulation (SQL/Python)
Data Scientist
Meta
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Facebook stores friendships once per pair in either column order, and friend requests as directed events. Find the share of yesterday's friend requests that were sent to someone the sender was already friends with, a sign of a client bug.

Meta's friendship graph is usually stored as undirected edges with an arbitrary column order, which makes naive joins miss half the matches. The interviewer checks whether you normalize pairs before joining and keep the request grain intact.

What the Interviewer Expects
  • Normalizes both tables to (smaller_id, larger_id) with LEAST and GREATEST
  • Joins on the normalized pair, not on one direction
  • Requires the friendship to exist before the request time
  • Dedupes the friendship table in case both directions are stored
  • Computes the share with the right denominator
Key Topics to Cover
pair normalization
LEAST/GREATEST
undirected edges
LEFT JOIN
data quality
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 would you check whether the friendship table actually stores both directions?
  • What if friendships can end, with an ended_at column?
  • How would you break the bug rate down by app version?
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

friendships(user_a, user_b, created_at): one row per pair, but which id lands in user_a is arbitrary, and some legacy rows exist in both orders. `friend_requests(request_id, sender_id, recipient_i...

Approach

Normalize every pair into (lo, hi) using LEAST and GREATEST, dedupe the friendship side to one row per pair with the earliest created_at, then LEFT JOIN requests onto it. Use a flag rather tha...


Submit Your Answer
Markdown supported