← Meta Interview Insights

Meta·Data Scientist·Technical Phone Screen·Senior

Senior
Jul 2026

Summary

Meta DS technical screen, all SQL, no fluff. Three questions off one schema and they just let you cook. The queries got progressively nastier and I definitely fumbled the percentile one before recovering.

Questions Asked (3)

Q1

Given a schema with users, posts, and comments, write a query to return the top 3 posts by distinct commenter count within a 7-day window, excluding deleted comments. Break ties by newer post date, then lower post_id. Include a count of distinct commenter countries.

Product Analytics & MetricsData Modeling
Author's notes

The tie-breaking tripped me up a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and definitions (e.g., what counts as a 'commenter', how to handle deleted comments, and the 7-day window relative to post date). Then build the query in stages: filter comments, join with posts and users, aggregate distinct commenter counts and countries per post, and finally rank and select the top 3 with the specified tie-breaking rules.

Pro tip: Explicitly state your assumptions about the schema (e.g., commenter_id, country, is_deleted, post_date) and the 7-day window (e.g., comments within 7 days after post creation). This shows you think about data nuances and prevents misalignment with the interviewer.

1. Clarify requirements and schema

Ask about table structures, column names, and definitions: what is a 'commenter' (user who commented), how to identify deleted comments, and whether the 7-day window is relative to post creation or current date. Confirm tie-breaking rules.

2. Filter and join relevant data

Filter out deleted comments and restrict to comments within the 7-day window. Join comments with posts to get post details and with users to get commenter country.

3. Aggregate per post

Group by post_id and compute COUNT(DISTINCT commenter_id) as distinct_commenter_count and COUNT(DISTINCT country) as distinct_country_count. Ensure you handle potential NULLs or duplicates appropriately.

4. Rank and select top 3

Use a window function (e.g., ROW_NUMBER() or RANK()) to order posts by distinct_commenter_count DESC, post_date DESC, post_id ASC. Then select the top 3 rows.

5. Validate and explain

Walk through the query logic, check edge cases (e.g., posts with no comments, ties), and discuss performance considerations (indexes, partitioning).

Key Points to Mention

  • Use COUNT(DISTINCT commenter_id) to count unique commenters per post, not total comments.
  • Filter deleted comments early (e.g., WHERE is_deleted = FALSE) to avoid skewing counts.
  • Define the 7-day window precisely: e.g., comments where comment_date BETWEEN post_date AND post_date + INTERVAL '7 days'.
  • Use window functions like ROW_NUMBER() or RANK() with ORDER BY distinct_commenter_count DESC, post_date DESC, post_id ASC to handle ties.
  • Count distinct countries with COUNT(DISTINCT country) from the commenter's user profile.
  • Consider performance: join order, indexing on post_id, comment_date, and is_deleted.

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

Q2

For each post and day within the same 7-day window, compute the P50 and P90 of comment text length over non-deleted comments using percentile_cont. Output one row per post per day, only for days that have at least one qualifying comment.

Product Analytics & MetricsData Modeling
Author's notes

Blanked for a second on the percentile_cont syntax.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and definitions: identify the post ID, comment timestamp, comment text, and deletion flag. Then write a SQL query that filters non-deleted comments, extracts the day from the comment timestamp, groups by post and day, and uses percentile_cont(0.5) and percentile_cont(0.9) to compute the P50 and P90 of text length. Ensure you only include days with at least one qualifying comment by using a HAVING clause or by filtering after aggregation.

Pro tip: Mention that percentile_cont is an ordered-set aggregate that interpolates between values, which is important for small sample sizes; also note that you should use the comment's creation date, not the post's date, to define the day.

1. Clarify schema and definitions

Identify the relevant tables and columns: post ID, comment ID, comment text, comment timestamp, and deletion flag. Confirm what 'non-deleted' means (e.g., is_deleted = false) and how to compute text length (e.g., LENGTH(text) or CHAR_LENGTH(text)).

2. Filter and prepare data

Filter out deleted comments and extract the day from the comment timestamp (e.g., DATE(created_at)). Ensure you only consider comments within the same 7-day window per post, if that is a requirement (though the question says 'within the same 7-day window' which might imply grouping by day within a 7-day period).

3. Group and aggregate

Group by post ID and day. Use percentile_cont(0.5) WITHIN GROUP (ORDER BY text_length) and percentile_cont(0.9) WITHIN GROUP (ORDER BY text_length) to compute P50 and P90. Apply a HAVING COUNT(*) > 0 to ensure at least one qualifying comment.

4. Format output

Select post ID, day, P50, and P90 as columns. Order the results by post ID and day for readability. Consider rounding the percentiles if needed.

Key Points to Mention

  • Use of percentile_cont for continuous percentiles (interpolated) vs. percentile_disc for discrete.
  • Filtering non-deleted comments before aggregation.
  • Grouping by post and day, and ensuring only days with at least one comment are included.
  • Handling of text length: use LENGTH or CHAR_LENGTH depending on database.
  • Potential need to handle NULL or empty comment texts.
  • Performance considerations: indexing on post_id and comment timestamp, and avoiding unnecessary sorting.

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

Q3

Identify users who commented on their own posts within the 7-day window. Return user_id, the count of such self-comments, and the timestamp of the most recent one. Order by self-comment count descending, then user_id ascending.

Product Analytics & MetricsData Modeling
Author's notes

This one was actually the cleanest to write.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema: posts (post_id, user_id, post_timestamp) and comments (comment_id, post_id, user_id, comment_timestamp). Then, join comments to posts on post_id, filter for comments where the commenter is the post author and the comment timestamp falls within 7 days of the post timestamp (or within the last 7 days from a reference date, depending on interpretation). Finally, aggregate by user_id to count self-comments and find the max comment timestamp, then sort as specified.

Pro tip: Always clarify the definition of '7-day window'—whether it's relative to the post creation date or a fixed recent period—and confirm the time granularity (e.g., days vs. hours) to avoid off-by-one errors.

1. Clarify the schema and definitions

Identify the tables (e.g., posts, comments) and their columns. Confirm what '7-day window' means: is it the last 7 days from today, or within 7 days after the post was created? Also clarify if 'self-comment' means the post author commenting on their own post.

2. Join comments to posts

Join the comments table to the posts table on post_id to associate each comment with its post and the post author.

3. Filter for self-comments within the window

Apply conditions: commenter user_id equals post author user_id, and comment timestamp is within the specified 7-day window (e.g., comment_timestamp BETWEEN post_timestamp AND post_timestamp + INTERVAL '7 days' or comment_timestamp >= CURRENT_DATE - INTERVAL '7 days').

4. Aggregate by user

Group by user_id to compute COUNT(*) as self_comment_count and MAX(comment_timestamp) as most_recent_self_comment.

5. Order and format results

Sort by self_comment_count descending, then user_id ascending. Return the required columns: user_id, self_comment_count, most_recent_self_comment.

Key Points to Mention

  • Schema assumptions: tables and columns (e.g., posts: post_id, user_id, post_timestamp; comments: comment_id, post_id, user_id, comment_timestamp).
  • Definition of '7-day window': relative to post creation vs. fixed recent period; importance of clarifying with interviewer.
  • Join condition: comments.post_id = posts.post_id.
  • Filter condition: comments.user_id = posts.user_id AND comment_timestamp within the window.
  • Aggregation: COUNT(*) for self-comment count, MAX(comment_timestamp) for most recent.
  • Ordering: ORDER BY self_comment_count DESC, user_id ASC.

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