← Meta Interview Insights

Meta·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
May 2026Remote

Summary

Meta DS technical screen, two SQL questions back to back on a shared schema. Both involved deduplication logic which is where things got tricky for me.

Questions Asked (2)

Q1

Given a views table with possible duplicate same-day rows per viewer, write a SQL query that returns the count of distinct posts that had at least one view from an unconnected user lasting more than 60 seconds, within a specified 7-day window.

Product Analytics & MetricsData Modeling
Author's notes

The dedup part is what caught me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and definitions (e.g., what 'unconnected' means, how to identify same-day duplicates, and the exact 7-day window). Then build the query in layers: filter views by duration and date, join to a connections table to exclude connected users, and finally count distinct posts. Use DISTINCT on post_id to handle duplicates and ensure each post is counted once.

Pro tip: Explicitly state your assumptions about the data model (e.g., connections are bidirectional, view duration is in seconds) and mention that you would validate the query with edge cases like boundary dates and users with multiple views. This shows you think about data quality and reproducibility.

1. Clarify requirements and schema

Ask about the table structures (views, users, connections), definitions of 'unconnected', 'same-day duplicate', and the exact 7-day window (inclusive/exclusive). Confirm that 'lasting more than 60 seconds' means duration > 60.

2. Filter views by duration and date

Select views where duration > 60 and view_date is within the specified 7-day window. Use a subquery or CTE to isolate these views.

3. Identify unconnected users

Join the filtered views to a connections table (or use NOT EXISTS) to exclude viewers who are connected to the post's author. Ensure the join handles bidirectional connections if needed.

4. Count distinct posts

From the resulting set, count distinct post_id to get the number of posts with at least one qualifying view. Use COUNT(DISTINCT post_id) to avoid duplicates from multiple views.

5. Validate and optimize

Check for edge cases (e.g., views on the boundary dates, null connections) and consider indexing on date and duration for performance. Explain how you would test the query.

Key Points to Mention

  • Use of COUNT(DISTINCT post_id) to handle duplicate same-day rows per viewer.
  • Definition and handling of 'unconnected' users (e.g., via a connections table with a NOT EXISTS or LEFT JOIN ... WHERE connection IS NULL).
  • Filtering by duration > 60 seconds and the specified 7-day window (using BETWEEN or >= and <).
  • Potential need to deduplicate views per user per post per day before counting, but DISTINCT on post_id suffices for the final count.
  • Assumptions about the schema: views table has viewer_id, post_id, view_date, duration; connections table has user_id1, user_id2.
  • Performance considerations: indexing on view_date and duration, and using CTEs for readability.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

For the same 7-day window, compute the average reactions per post for Friend-labeled viewers and Unconnected-labeled viewers separately. Reactions should be attributed to a view using a join on post_id, viewer_id, and date, and same-day duplicate views should be resolved by keeping the longest duration. The denominator should be distinct posts with at least one view from that group, including posts with zero reactions.

Product Analytics & MetricsData ModelingRoot Cause Analysis
Author's notes

This one was harder than it looked.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, deduplicate views by keeping the longest duration per post_id, viewer_id, and date, then join reactions on those same keys. Next, aggregate reactions per post per viewer group, and compute the average by dividing total reactions by the distinct count of posts with at least one view in that group, ensuring posts with zero reactions are included.

Pro tip: Explicitly state that you will use a LEFT JOIN from the deduplicated views to reactions and COALESCE zero reactions, because this is a common pitfall that can exclude posts with no reactions and skew the average upward.

1. Deduplicate views

For each post_id, viewer_id, and date, keep only the row with the longest duration to resolve same-day duplicate views.

2. Join reactions

Left join the deduplicated views to the reactions table on post_id, viewer_id, and date, so that views without reactions are retained with zero reactions.

3. Aggregate per post and group

Group by post_id and viewer group (Friend vs. Unconnected), summing reactions per post and counting distinct posts with at least one view.

4. Compute average

For each group, divide the total reactions by the distinct count of posts with at least one view, ensuring posts with zero reactions are included in both numerator and denominator.

Key Points to Mention

  • Deduplication logic: keep the longest duration per post_id, viewer_id, and date.
  • Join keys: post_id, viewer_id, and date to attribute reactions to views.
  • Use LEFT JOIN and COALESCE to include posts with zero reactions.
  • Denominator: distinct count of posts with at least one view from the group.
  • Separate calculations for Friend-labeled and Unconnected-labeled viewers.
  • 7-day window filter applied consistently to views and reactions.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.