← Meta Interview Insights

Meta·Data Scientist·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Meta data scientist SQL round, two tasks in one problem set. The question was dense and the edge cases were the whole point, not an afterthought.

Questions Asked (2)

Q1

Given two tables tracking post views and reactions, write SQL to count distinct posts that had at least one view from an unconnected user lasting more than 60 seconds in a 7-day window. If the same user viewed the same post multiple times on the same day, deduplicate by taking the max duration before applying the filter.

Product Analytics & MetricsData Modeling
Author's notes

The dedup step tripped me up at first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and the definition of 'unconnected user' (e.g., not in the user's network). Then write a SQL query that first deduplicates view events by user, post, and day using MAX(duration), filters for duration > 60 seconds and unconnected users, and finally counts distinct posts within the 7-day window.

Pro tip: Explicitly state your assumptions about the data model (e.g., how connections are represented) and mention that you would validate the deduplication logic with a sample query before finalizing. This shows you think about data quality and edge cases.

1. Clarify requirements and schema

Ask about the table structures, how 'unconnected' is defined (e.g., via a connections table), and the exact 7-day window (e.g., rolling or fixed). Confirm that duration is in seconds and that reactions table is not needed for this specific count.

2. Deduplicate views per user, post, and day

Use a subquery or CTE to group by user_id, post_id, and DATE(view_time), taking MAX(duration) to handle multiple views on the same day. This ensures each user-post-day combination is represented once with the longest duration.

3. Filter for unconnected users and duration > 60 seconds

Join with a connections table (or use a NOT EXISTS clause) to exclude users connected to the post author, and apply the condition duration > 60. Be careful with NULLs and ensure the join logic correctly identifies unconnected users.

4. Apply 7-day window and count distinct posts

Restrict the filtered events to the last 7 days (e.g., WHERE view_date >= CURRENT_DATE - INTERVAL '7 days') and then count distinct post_id. Use COUNT(DISTINCT post_id) to get the final metric.

5. Validate and optimize

Check for edge cases (e.g., users with no connections, posts with no views) and consider indexing on view_time, user_id, and post_id for performance. Optionally, discuss how to handle time zones if relevant.

Key Points to Mention

  • Deduplication logic: using MAX(duration) per user, post, and day to avoid double-counting.
  • Definition of 'unconnected user': likely requires a separate connections table and a LEFT JOIN or NOT EXISTS to filter out connected users.
  • Time window: specifying the 7-day range, possibly using DATE_SUB or INTERVAL, and ensuring it's relative to the current date or a given date.
  • Counting distinct posts: using COUNT(DISTINCT post_id) after filtering.
  • Performance considerations: indexing on view_time, user_id, and post_id; avoiding unnecessary joins with the reactions table.
  • Assumptions and edge cases: e.g., what if a user views a post multiple times on different days? The deduplication is per day, so multiple days count separately, but we only need distinct posts.

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

Q2

Using the same two tables and 7-day window, compute the average reactions per post for Friend vs Unconnected viewers. Join reactions to views on post_id, viewer_id, and ds. When multiple view rows match a single reaction, use the one with the highest duration. The denominator should be all distinct posts that appeared in views for that group, including posts with zero reactions.

Product Analytics & MetricsData ModelingTechnical Trade-offs
Author's notes

This one is genuinely hard to get right in one pass.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, deduplicate views by selecting the row with the highest duration for each (post_id, viewer_id, ds) combination. Then, left join reactions to the deduplicated views on post_id, viewer_id, and ds, ensuring all distinct posts from views are included. Finally, compute the average reactions per post for each viewer group (Friend vs Unconnected) by dividing total reactions by the count of distinct posts in views for that group.

Pro tip: Clarify the definition of 'Friend vs Unconnected'—likely based on a relationship flag in the views table—and confirm that the denominator counts distinct posts, not view events, to avoid inflating the average.

1. Deduplicate views

Use a window function (e.g., ROW_NUMBER() OVER (PARTITION BY post_id, viewer_id, ds ORDER BY duration DESC)) to select the view row with the highest duration for each unique combination.

2. Left join reactions to deduplicated views

Join the deduplicated views to the reactions table on post_id, viewer_id, and ds, ensuring that all view rows are retained even if there are no matching reactions.

3. Aggregate reactions and distinct posts per group

Group by viewer group (Friend vs Unconnected) and compute the total number of reactions (e.g., COUNT(reaction_id)) and the count of distinct posts from views (e.g., COUNT(DISTINCT post_id)).

4. Calculate average reactions per post

Divide the total reactions by the distinct post count for each group to get the average reactions per post.

Key Points to Mention

  • Deduplication of views using highest duration to resolve multiple view rows per reaction.
  • Use of LEFT JOIN to ensure posts with zero reactions are included in the denominator.
  • Denominator is the count of distinct posts in views for each group, not the number of view events.
  • Grouping by viewer relationship type (Friend vs Unconnected) as defined in the views table.
  • Handling of potential NULLs from the left join when counting reactions (e.g., COUNT(reaction_id) ignores NULLs).
  • Ensuring the 7-day window is applied consistently to both views and reactions.

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