← Meta Interview Insights

Meta·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Feb 2023Remote

Summary

Meta DS interview with a heavy SQL focus, three questions all built around the same Calls and Users schema. The cycle detection one was genuinely tricky and I don't think I nailed it.

Questions Asked (3)

Q1

Write a SQL query that returns the number of distinct users who initiated calls to more than three unique recipients in the past seven days.

Product Analytics & MetricsData Modeling
Author's notes

Pretty standard GROUP BY/HAVING setup.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and definitions (e.g., what constitutes a call, how to identify initiators and recipients, and the time window). Then write a query that groups by caller and counts distinct recipients within the last 7 days, filtering for those with more than 3 distinct recipients, and finally counts the number of such callers.

Pro tip: Mention that you would confirm whether 'past seven days' means the last 7*24 hours or calendar days, and whether the call must have been initiated within that period or just occurred. Also, consider if there are any edge cases like calls to oneself or null recipients.

1. Clarify requirements and schema

Ask about the table structure, column names, and definitions: what identifies a user, a call, the initiator, the recipient, and the timestamp. Confirm the exact meaning of 'past seven days' and 'unique recipients'.

2. Filter calls in the time window

Use a WHERE clause to restrict to calls initiated in the last 7 days, based on the call timestamp. Ensure the timestamp is in the correct timezone if relevant.

3. Group by caller and count distinct recipients

Group the filtered calls by the initiator (caller) and count the distinct recipients for each caller. Use COUNT(DISTINCT recipient_id) to avoid double-counting.

4. Filter callers with more than 3 distinct recipients

Apply a HAVING clause to keep only those callers whose distinct recipient count exceeds 3.

5. Count the number of such callers

Wrap the previous result in a subquery or use a COUNT over the filtered groups to return the total number of distinct users who meet the criteria.

Key Points to Mention

  • Use COUNT(DISTINCT recipient_id) to ensure unique recipients are counted per caller.
  • Filter calls by timestamp to only include those in the past 7 days (e.g., WHERE call_time >= CURRENT_DATE - INTERVAL '7 days').
  • Group by caller ID and apply HAVING COUNT(DISTINCT recipient_id) > 3.
  • Consider whether to exclude calls where the recipient is the caller themselves or where recipient is NULL.
  • Use a subquery or CTE to first get qualifying callers, then count them.
  • Discuss potential performance considerations, such as indexing on call_time and caller_id.

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

Q2

Calculate the percentage of yesterday's daily active users from France who participated in at least one video call.

Product Analytics & MetricsData Modeling
Author's notes

Needed to join Calls and Users, filter dau_flag = 1 and country = 'fr' and ds = yesterday, then figure out who appeared as either caller or recipient in a call that day.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the definitions of 'daily active user', 'participated in at least one video call', and 'yesterday' to ensure alignment. Then outline the data sources and steps to compute the numerator (DAU from France who had ≥1 video call) and denominator (total DAU from France), and finally calculate the percentage. Consider edge cases like time zones and data completeness.

Pro tip: Proactively mention that you would validate the metric by checking for data anomalies (e.g., spikes or drops) and consider segmenting by device or call type to provide deeper insights, showing you think beyond the basic calculation.

1. Clarify Definitions

Define 'daily active user' (e.g., logged-in user who performed any activity), 'participated in a video call' (e.g., initiated or joined a call), and 'yesterday' (e.g., UTC date). Confirm with stakeholders if ambiguous.

2. Identify Data Sources

Determine which tables or logs contain user activity and video call events, such as a DAU table and a video call events table. Ensure they can be joined on user ID and date.

3. Compute Numerator and Denominator

Write SQL queries to count distinct users from France who were active yesterday (denominator) and those among them who had at least one video call (numerator). Use appropriate filters for country and date.

4. Calculate Percentage

Divide the numerator by the denominator and multiply by 100 to get the percentage. Handle potential division by zero (e.g., if no DAU from France).

5. Validate and Interpret

Check for data quality issues (e.g., missing data, time zone mismatches) and consider if the result makes sense. Optionally, segment by dimensions like age or device to provide context.

Key Points to Mention

  • Definition of daily active user (DAU) and how it's measured at Meta (e.g., any activity vs. specific actions).
  • Definition of 'participated in a video call' (e.g., initiated, received, or joined a call) and whether it includes missed calls.
  • Time zone considerations: 'yesterday' in which time zone? France vs. UTC vs. user's local time.
  • Data sources: likely need to join user activity data with video call event data, ensuring both are filtered for France and yesterday.
  • SQL implementation: using COUNT(DISTINCT user_id) with appropriate WHERE clauses and JOINs.
  • Edge cases: users with multiple calls, users who are active but not in France, data latency or incomplete logs for yesterday.

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

Q3

Using only the Calls table, write SQL to detect three-person call cycles where A called B, B called C, and C called A.

Algorithms & Data StructuresData Modeling
Author's notes

This one sat me down.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use three self-joins on the Calls table to find paths A→B→C→A, ensuring all three callers are distinct. Filter for the cycle condition and return each cycle once by enforcing an ordering (e.g., A < B < C) to avoid duplicates.

Pro tip: Clarify the schema first (e.g., caller, callee, timestamp) and mention that if the table has multiple rows per pair, you may need to deduplicate or consider time ordering. Also, discuss how to scale the query for large datasets, as self-joins can be expensive.

1. Understand the schema and requirements

Identify the relevant columns (e.g., caller, callee) and confirm that the table may have multiple calls between the same pair. Clarify that a cycle requires three distinct people and directed edges A→B, B→C, C→A.

2. Design the self-join strategy

Plan to join the Calls table to itself three times: first for A→B, second for B→C, third for C→A. Use aliases to distinguish the instances.

3. Write the SQL with join conditions

Construct the query: SELECT ... FROM Calls c1 JOIN Calls c2 ON c1.callee = c2.caller JOIN Calls c3 ON c2.callee = c3.caller WHERE c3.callee = c1.caller AND c1.caller < c1.callee AND c1.callee < c2.callee (or similar) to ensure distinctness and avoid duplicates.

4. Handle duplicates and output format

Use DISTINCT or a canonical ordering (e.g., A < B < C) to return each cycle only once. Decide whether to output the three names or just a count, based on the question.

5. Test and optimize

Mentally test with sample data to ensure correctness. Discuss potential performance improvements, such as indexing on caller and callee, or using a graph database for large-scale cycle detection.

Key Points to Mention

  • Self-joins on the Calls table to represent the three edges of the cycle.
  • Ensuring distinctness of A, B, and C to avoid trivial cycles (e.g., A→A).
  • Using inequalities (e.g., A < B < C) to eliminate duplicate cycles and enforce a canonical order.
  • Handling multiple calls between the same pair (e.g., using DISTINCT or aggregating).
  • Performance considerations: indexing, query complexity, and alternatives for large datasets.
  • Clarifying assumptions about the schema and data (e.g., directed edges, no self-loops).

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