← Meta Interview Insights

Meta·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Sep 2023Remote

Summary

Meta DS interview focused on SQL and analytics for a WhatsApp use case. Pretty standard technical phone screen stuff but the country-filtering + DAU percentage question had a small wrinkle that tripped me up a bit.

Questions Asked (4)

Q1

Write a SQL query to find the number of unique users who initiated a call with more than 3 participants within the last 7 days.

Product Analytics & MetricsData Modeling
Author's notes

Felt fine about this one.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the schema and definitions (e.g., what constitutes a call, how participants are tracked, and what 'initiated' means). Then, write a SQL query that joins call and participant tables, filters calls with >3 participants in the last 7 days, and counts distinct initiators. Use a subquery or CTE to aggregate participant counts per call before filtering.

Pro tip: Always confirm the time zone and whether 'last 7 days' includes today; also discuss how to handle calls with missing participant data or duplicate entries.

1. Clarify requirements and schema

Ask about table structures (e.g., calls, participants, users), definitions of 'initiated', 'unique users', and 'last 7 days'. Confirm if participants include the initiator.

2. Filter calls by time and participant count

Use a subquery or CTE to select calls from the last 7 days and count participants per call, then filter for calls with more than 3 participants.

3. Identify initiators of qualifying calls

Join the filtered calls back to the calls table (or directly if initiator is in the calls table) to get the user who initiated each call.

4. Count distinct initiators

Use COUNT(DISTINCT user_id) to get the number of unique users who initiated at least one qualifying call.

5. Validate and optimize

Check for edge cases (e.g., calls with exactly 3 participants, time zone issues) and consider indexing or partitioning for performance.

Key Points to Mention

  • Definition of 'initiated': ensure it's the user who started the call, not just a participant.
  • Handling of time zones and date boundaries for 'last 7 days'.
  • Use of COUNT(DISTINCT) to get unique users.
  • Potential need to exclude the initiator from participant count if the schema includes them.
  • Performance considerations: filtering early, using indexes, and avoiding unnecessary joins.
  • Edge cases: calls with exactly 3 participants, missing data, or duplicate participant records.

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

Q2

Write SQL to calculate what percentage of yesterday's daily active users in France were on a video call.

Product Analytics & MetricsData Modeling
Author's notes

This one got messy for me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the definitions of 'daily active user' and 'on a video call' with the interviewer, then outline the SQL logic: filter users active yesterday in France, identify those who were on a video call, and compute the percentage. Write a query using a CTE or subquery to count distinct users in each category, then divide and multiply by 100.

Pro tip: Mention that you would validate the result by checking edge cases, such as users with multiple calls or missing country data, and discuss how to handle time zones if the data is stored in UTC.

1. Clarify Definitions and Assumptions

Confirm with the interviewer what constitutes a 'daily active user' (e.g., any activity or specific actions) and what qualifies as 'on a video call' (e.g., call duration, call type). Also clarify the date range for 'yesterday' and how to handle time zones.

2. Identify Relevant Tables and Columns

Determine which tables contain user activity, video call events, and user location data. Assume a simplified schema: a user_activity table with user_id, activity_date, and country, and a video_calls table with user_id, call_date, and call_type.

3. Write SQL to Compute the Percentage

Use a CTE to select distinct users active yesterday in France, then left join to video call events to flag those on a call. Compute the percentage as (number of users on a video call / total active users) * 100.

4. Validate and Discuss Edge Cases

Mention potential issues like duplicate call records, users with multiple calls, or missing country information. Discuss how to handle them, e.g., using DISTINCT or filtering by call duration.

Key Points to Mention

  • Definition of daily active user (DAU) and video call engagement
  • Use of DISTINCT to count unique users
  • Filtering by date and country (e.g., activity_date = CURRENT_DATE - 1 AND country = 'France')
  • Handling time zones if data is stored in UTC
  • Using LEFT JOIN to include all active users and flag those with video calls
  • Calculating percentage with proper rounding and avoiding division by zero

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

Q3

Is COUNT(DISTINCT user_id) still necessary when you've already grouped by user_id?

Technical Trade-offsData Modeling
Author's notes

Short answer: no, not really.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that the necessity depends on the query structure: if you group by user_id, each group represents a unique user, so COUNT(DISTINCT user_id) is redundant and equivalent to COUNT(user_id) or COUNT(*). However, if you need to count distinct users per group after grouping by another dimension, then COUNT(DISTINCT user_id) is essential. Emphasize that the answer hinges on the grouping level and the desired output.

Pro tip: Mention that COUNT(DISTINCT) can be slower and more memory-intensive than COUNT, so avoiding it when unnecessary is a performance best practice. Also, note that in some databases, COUNT(DISTINCT) may ignore NULLs, which could affect results if user_id is nullable.

1. Clarify the grouping context

Determine what columns are in the GROUP BY clause. If user_id is the only grouping column, each group is a single user.

2. Explain redundancy when grouping by user_id

When grouping by user_id, COUNT(DISTINCT user_id) is redundant because each group has exactly one distinct user_id; COUNT(user_id) or COUNT(*) would yield the same result.

3. Identify when COUNT(DISTINCT) is necessary

If grouping by another dimension (e.g., date), COUNT(DISTINCT user_id) is needed to count unique users per group, as multiple rows per user may exist.

4. Discuss performance and semantic implications

Highlight that COUNT(DISTINCT) is more resource-intensive and may have different NULL handling; using it unnecessarily can degrade performance.

5. Summarize with a clear rule of thumb

Conclude that COUNT(DISTINCT user_id) is only necessary when the grouping does not already guarantee uniqueness of user_id within each group.

Key Points to Mention

  • Grouping by user_id makes each group correspond to a single user, so COUNT(DISTINCT user_id) is redundant.
  • COUNT(DISTINCT) is necessary when counting unique users per group after grouping by another column (e.g., date, country).
  • COUNT(DISTINCT) can be slower and more memory-intensive than COUNT, so avoid it when possible.
  • NULL handling: COUNT(DISTINCT) ignores NULLs, while COUNT(user_id) also ignores NULLs, but COUNT(*) does not.
  • In some databases, COUNT(DISTINCT) may have limitations or different performance characteristics.
  • Always consider the query's intent: are you counting rows or unique entities?

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

Q4

What is the difference between UNION and UNION ALL, and when would you use one over the other?

Technical Trade-offsAlgorithms & Data Structures
Author's notes

UNION deduplicates rows, UNION ALL keeps everything including duplicates.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clearly defining UNION and UNION ALL, emphasizing that UNION removes duplicates while UNION ALL does not. Then discuss the performance implications and when to use each, focusing on trade-offs between correctness and efficiency. Finally, relate it to a data science context, such as combining datasets from different sources.

Pro tip: Mention that UNION ALL is often preferred in big data pipelines because it avoids the costly deduplication step, and you can always deduplicate later if needed. This shows awareness of scalability and cost.

1. Define UNION

Explain that UNION combines results from two queries and removes duplicate rows, effectively performing a distinct operation.

2. Define UNION ALL

Explain that UNION ALL combines results without removing duplicates, simply concatenating the rows.

3. Compare performance

Discuss that UNION requires sorting or hashing to eliminate duplicates, making it slower and more resource-intensive than UNION ALL.

4. When to use each

Use UNION when you need distinct rows and duplicates are not meaningful; use UNION ALL when duplicates are acceptable or when you plan to deduplicate later, especially for performance.

5. Relate to data science

Give an example, such as combining user logs from different days where duplicates might occur, and explain how you'd choose based on the analysis goal.

Key Points to Mention

  • UNION removes duplicates, UNION ALL does not.
  • UNION typically involves a distinct operation, which can be expensive.
  • UNION ALL is faster and less resource-intensive.
  • Use UNION when you need a unique set of rows.
  • Use UNION ALL when duplicates are acceptable or when you can deduplicate later.
  • In big data contexts, UNION ALL is often preferred for scalability.

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