← Meta Interview Insights

Meta·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Sep 2023Remote

Summary

Meta Data Scientist SQL round, two questions back to back using a social media analytics schema. Pretty standard stuff but the second one had a small twist that slowed me down a bit.

Questions Asked (2)

Q1

Given a views table with viewer connection type and view duration, write a query to find the count of distinct posts that accumulated more than 60 total seconds of view time from unconnected viewers in the past 7 days.

Product Analytics & MetricsAlgorithms & Data Structures
Author's notes

Straightforward filter-group-having pattern.

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 handle NULLs, time zone for 'past 7 days'). Then write a SQL query that filters views from the last 7 days where connection_type = 'unconnected', groups by post_id, sums view_duration, and counts distinct post_ids where the sum exceeds 60 seconds.

Pro tip: Mention that you would validate the query by checking edge cases like posts with exactly 60 seconds (should be excluded) and ensuring the date filter uses the correct time zone. Also, discuss performance considerations such as indexing on date and connection_type.

1. Clarify requirements and schema

Ask about the table schema, definition of 'unconnected' (e.g., connection_type = 'unconnected'), time zone for 'past 7 days', and whether view_duration is in seconds.

2. Filter relevant rows

Use a WHERE clause to select views from the last 7 days and where connection_type indicates unconnected viewers.

3. Aggregate view time per post

Group by post_id and sum view_duration to get total view time per post.

4. Apply threshold and count distinct posts

Use a HAVING clause to filter posts with total view time > 60 seconds, then count distinct post_ids.

5. Validate and optimize

Check edge cases (e.g., exactly 60 seconds) and discuss indexing or partitioning for performance.

Key Points to Mention

  • Definition of 'unconnected' viewers (e.g., connection_type = 'unconnected')
  • Time zone handling for 'past 7 days' (e.g., UTC or local time)
  • Use of SUM(view_duration) and HAVING SUM(view_duration) > 60
  • Counting distinct post_ids to avoid duplicates
  • Handling NULLs or missing data in view_duration or connection_type
  • Performance considerations: indexing on date and connection_type, partitioning by date

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

Q2

Write a query to compute the average number of reactions received by posts from friend-connected creators versus unconnected-creator posts in the last 7 days.

Product Analytics & MetricsData Modeling
Author's notes

This one required joining the views table to the actions table to pull in connection type alongside reaction counts.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the definitions of 'friend-connected creators' and 'unconnected-creator posts' and confirm the time window. Then, write a SQL query that joins posts with friendship data, filters to the last 7 days, and computes the average reactions per post for each group, ensuring proper aggregation and handling of edge cases.

Pro tip: Mention that you would validate the friendship connection using the most recent state (e.g., current friends) and consider using a LEFT JOIN to include posts with zero reactions, as excluding them could bias the average upward.

1. Clarify definitions and assumptions

Define what constitutes a 'friend-connected creator' (e.g., the post creator is a friend of the viewer) and 'unconnected-creator posts'. Confirm the time window (last 7 days) and the reaction metric (e.g., total reactions per post).

2. Identify relevant tables and fields

Determine the tables needed: posts (with creator_id, post_id, timestamp), reactions (post_id, reaction_type), and friendships (user_id, friend_id, status). Ensure you have the necessary join keys.

3. Construct the join and filter

Join posts with friendships on creator_id = friend_id and user_id = viewer_id (or similar), filter posts to the last 7 days, and left join reactions to count reactions per post. Use a CASE statement to flag connected vs. unconnected.

4. Aggregate and compute averages

Group by the connection flag and compute the average number of reactions per post. Ensure you handle posts with zero reactions by using LEFT JOIN and COALESCE to treat nulls as zero.

5. Validate and interpret results

Check for data quality issues (e.g., duplicate friendships, missing timestamps) and consider if the average should be weighted by user or post. Discuss potential confounders and how to interpret the difference.

Key Points to Mention

  • Definition of friend-connected creators: likely based on the viewer's friendship graph, but could also be based on the post creator's connections.
  • Time window: filter posts with timestamp >= current_date - interval '7 days'.
  • Handling posts with zero reactions: use LEFT JOIN and COALESCE to avoid excluding them from the average.
  • Aggregation level: average reactions per post, not per user, unless specified otherwise.
  • Potential bias: if friend-connected posts are more likely to receive reactions, the average may be higher; consider controlling for post age or creator popularity.
  • SQL structure: use CASE WHEN to categorize posts, then GROUP BY category and AVG(reaction_count).

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