← Meta Interview Insights

Meta·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Sep 2023Remote

Summary

Meta DS technical screen, SQL heavy. Two questions back to back using the same two tables, which I wasn't expecting. Felt more like a take-home graded in real time than a conversation.

Questions Asked (2)

Q1

Using the info_stream_views table, write a SQL query to find the number of distinct posts that had more than 60 seconds of viewing time from unconnected viewers in the past 7 days.

Product Analytics & MetricsData Modeling
Author's notes

Straightforward filter-and-count but I initially forgot to filter on the relationship column and just wrote a WHERE on duration and ds.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the schema and definitions (e.g., what 'unconnected' means, how viewing time is recorded). Then, write a SQL query that filters rows to the past 7 days and unconnected viewers, aggregates total viewing time per post, and counts distinct posts where the total exceeds 60 seconds.

Pro tip: Mention that you would verify the grain of the table (e.g., one row per view session) and consider using a subquery or CTE to first calculate total watch time per post, which makes the query more readable and avoids potential aggregation errors.

1. Clarify requirements and schema

Ask clarifying questions about the definition of 'unconnected viewers' (e.g., is there a connection_type column?), how viewing time is stored (e.g., watch_time_seconds per row), and the exact time window (e.g., last 7 days from today).

2. Filter relevant rows

Use a WHERE clause to restrict to the past 7 days (e.g., view_date >= CURRENT_DATE - INTERVAL '7 days') and to unconnected viewers (e.g., connection_type = 'unconnected').

3. Aggregate viewing time per post

Group by post_id and sum the viewing time (e.g., SUM(watch_time_seconds)) to get total viewing time per post.

4. Filter posts with >60 seconds and count distinct

Apply a HAVING clause to keep only posts with total viewing time > 60 seconds, then count the distinct post_ids.

5. Write final query and consider edge cases

Combine steps into a single query, possibly using a subquery or CTE. Discuss handling of NULLs, timezone, and whether 'viewing time' might be spread across multiple rows per viewer.

Key Points to Mention

  • Definition of 'unconnected viewers' and how it is represented in the table (e.g., a flag or join to a connections table).
  • Time window calculation: using CURRENT_DATE or a specific date range, and considering timezone if applicable.
  • Aggregation: SUM of viewing time per post, and ensuring the correct grain (e.g., per view session).
  • Filtering with HAVING vs WHERE: HAVING is used after aggregation to filter groups.
  • Counting distinct posts: using COUNT(DISTINCT post_id) to avoid duplicates.
  • Performance considerations: indexing on date and connection_type, and avoiding unnecessary columns in SELECT.

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

Q2

Write a second query that returns the average number of reactions per post, broken out separately for friend viewers and unconnected viewers, over the past 7 days. You'll need to join the views and reactions tables.

Product Analytics & MetricsData Modeling
Author's notes

This one bit me a little.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the grain of the views and reactions tables and how they join (likely on post_id and viewer_id). Then, filter both tables to the last 7 days, join them, and compute the average reactions per post separately for friend and unconnected viewers, ensuring you handle posts with zero reactions appropriately.

Pro tip: Explicitly state your assumption about the join key and whether you're counting distinct posts or all view events; this shows you understand the data model and avoids double-counting.

1. Clarify table schemas and join keys

Identify the columns in the views and reactions tables, especially the post identifier, viewer identifier, and viewer type (friend/unconnected). Confirm the join key (e.g., post_id and viewer_id) and the time column for filtering.

2. Filter to last 7 days

Apply a date filter to both tables to include only records from the past 7 days, using the appropriate timestamp column (e.g., view_time, reaction_time).

3. Join views and reactions

Perform a LEFT JOIN from views to reactions on post_id and viewer_id to retain all views, even those without reactions, so that zero-reaction views are counted.

4. Aggregate reactions per post and viewer type

Group by post_id and viewer_type (friend/unconnected), count reactions (or sum a reaction indicator), and compute the average reactions per post for each viewer type.

5. Compute overall averages

If the question asks for the average across all posts, aggregate the per-post averages or compute directly: total reactions divided by total distinct posts, separately for friend and unconnected viewers.

Key Points to Mention

  • Handling posts with zero reactions by using LEFT JOIN or COALESCE to avoid dropping them.
  • Defining 'average reactions per post' as total reactions divided by total distinct posts, not average per view.
  • Ensuring the time window is applied consistently to both tables.
  • Using the correct viewer type classification from the views table (or a user dimension table).
  • Considering whether to count distinct reactions or all reaction events (e.g., multiple reactions per user).
  • Writing clear, readable SQL with comments explaining assumptions.

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