← Meta Interview Insights

Meta·Data Scientist·Technical Phone Screen·Senior

Senior
May 2026

Summary

SQL-heavy Data Scientist screen at Meta, four questions all centered on a shop visibility dataset with window functions, cohort analysis, and a stats reasoning piece at the end. Nothing behavioral, just raw SQL the whole way through.

Questions Asked (4)

Q1

Using a shop visibility table with timestamps, find the top 10 profiles by number of visibility flips (transitions where visibility changes from the previous state), breaking ties by smaller profile_id first.

Product Analytics & MetricsAlgorithms & Data Structures
Author's notes

LAG over ts partitioned by profile_id is the move here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a window function like LAG to compare each row's visibility with the previous row for the same profile, ordered by timestamp. Then count the number of transitions per profile, sort by count descending and profile_id ascending, and limit to 10.

Pro tip: Clarify the definition of a 'flip'—whether the first observation counts as a transition from NULL—and mention handling ties with a deterministic secondary sort. Also, consider performance implications for large datasets, suggesting partitioning by profile_id.

1. Understand the data and define a flip

Identify the columns: profile_id, timestamp, visibility. Define a flip as a change in visibility from the previous timestamp for the same profile. Decide if the first record counts as a flip (usually not).

2. Order and compare consecutive rows

Use a window function (e.g., LAG) partitioned by profile_id and ordered by timestamp to get the previous visibility value for each row.

3. Count flips per profile

Flag rows where visibility differs from the previous visibility (excluding the first row per profile). Then aggregate by profile_id to count the number of flips.

4. Rank and select top 10

Order the results by flip count descending, then by profile_id ascending to break ties. Limit the output to the top 10 profiles.

Key Points to Mention

  • Use of window functions (LAG) to access previous row values
  • Partitioning by profile_id and ordering by timestamp
  • Handling NULLs or first rows appropriately (e.g., using COALESCE or filtering)
  • Tie-breaking logic: ORDER BY flip_count DESC, profile_id ASC
  • Efficiency considerations for large datasets (e.g., indexing, partitioning)
  • Edge cases: profiles with only one record, missing timestamps, or duplicate timestamps

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

Q2

Calculate the percentage of shops currently visible as of a given date, where 'currently visible' means the shop's last recorded state at or before end of day is visibility=1. Return both the percentage and raw counts.

Product Analytics & MetricsData Modeling
Author's notes

Took me a second to figure out the right way to get the 'last state' per profile.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the schema and definitions: identify the shop table, the state history table with visibility and timestamp, and the given date. Then, for each shop, find the last state at or before the end of the given date, filter for visibility=1, and compute the percentage and raw counts.

Pro tip: Always confirm whether 'currently visible' should consider shops that have no state records at all—these might be excluded or counted as not visible depending on business rules. Also, be mindful of time zones and the exact definition of 'end of day'.

1. Clarify requirements and data model

Ask clarifying questions about the tables, columns, and definitions: what is the shop table, what is the state history table, how is visibility recorded, and what is the exact cutoff time (e.g., 23:59:59 in which time zone).

2. Identify the latest state per shop

For each shop, find the most recent record at or before the cutoff datetime using a window function like ROW_NUMBER() partitioned by shop_id and ordered by timestamp descending.

3. Filter for visibility=1 and count

From the latest state per shop, filter rows where visibility=1. Count the number of such shops and the total number of shops (or total shops with any state record, depending on definition).

4. Compute percentage and raw counts

Calculate the percentage as (visible shops / total shops) * 100. Also report the raw counts: number of visible shops and total shops considered.

5. Validate and handle edge cases

Check for shops with no state records, null visibilities, or multiple states at the exact cutoff. Decide how to handle these based on business rules and document assumptions.

Key Points to Mention

  • Use of window functions (e.g., ROW_NUMBER() or RANK()) to get the latest state per shop efficiently.
  • Definition of 'currently visible' as the last state at or before end of day, and how to handle ties or missing data.
  • Importance of clarifying the total denominator: all shops vs. shops with at least one state record.
  • Time zone considerations and the exact cutoff timestamp (e.g., 23:59:59.999).
  • Handling of shops with no state records: should they be counted as not visible or excluded?
  • Potential need to join with a shop dimension table to get the full list of shops.

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

Q3

Break down currently visible shops by category: for each shop_category, return the count of visible shops and its share of all currently visible shops.

Product Analytics & MetricsData Modeling
Author's notes

Pretty straightforward once you have the current visibility CTE from the previous question.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the definition of 'currently visible' (e.g., active status, not deleted, within date range) and the grain of the shops table. Then write a SQL query that filters to visible shops, groups by shop_category, counts the shops, and computes the percentage of total visible shops using a window function or subquery.

Pro tip: Mention that you would validate the results by checking that the sum of counts equals the total visible shops and that percentages sum to 100% (allowing for rounding). Also, consider edge cases like shops with null categories or categories with zero visible shops.

1. Clarify requirements and definitions

Confirm what 'currently visible' means (e.g., is_visible flag, status, date range) and the expected output format (e.g., category, count, percentage).

2. Identify relevant tables and filters

Determine the shops table and any necessary joins (e.g., to a status table) and apply the visibility filter.

3. Aggregate counts by category

Use GROUP BY shop_category to count the number of visible shops per category.

4. Compute share of total

Calculate the percentage by dividing each category count by the total visible shop count, using a window function or subquery.

5. Validate and present results

Check that counts sum to total and percentages sum to 100%, and format the output clearly.

Key Points to Mention

  • Definition of 'currently visible' (e.g., is_visible = true, status = 'active', not deleted)
  • Use of GROUP BY shop_category for aggregation
  • Calculation of percentage using window function (e.g., SUM(COUNT(*)) OVER ()) or subquery
  • Handling of NULL or missing categories
  • Validation checks: sum of counts equals total, percentages sum to 100%
  • Consideration of performance and indexing on visibility and category columns

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

Q4

Verify the hypothesis that newer shops are visible for fewer days. For each creation month cohort, compute each profile's fraction of days with final visibility=1 in its first 30 days since creation (deduping consecutive identical states), then return cohort-level profile count, median fraction, and P75/P25. Also explain how you'd handle profiles created less than 30 days before the analysis date, and how you'd test the trend statistically.

A/B Testing & ExperimentationProduct Analytics & MetricsData Modeling
Author's notes

This one took most of the time.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Break the problem into three parts: data preparation (deduping consecutive states and computing fractions), cohort aggregation (grouping by creation month and calculating count, median, P75, P25), and handling edge cases (incomplete 30-day windows and statistical testing). For the incomplete windows, discuss options like excluding them, using a fixed observation window, or survival analysis, and justify your choice. For statistical testing, propose a non-parametric trend test (e.g., Jonckheere-Terpstra) or regression on cohort-level medians, and mention multiple comparisons if needed.

Pro tip: Emphasize that deduping consecutive identical states is crucial to avoid inflating the fraction due to repeated daily snapshots; also note that using a fixed 30-day window ensures comparability across cohorts, but you must address censoring for recent cohorts.

1. Data Preparation and Deduplication

For each profile, sort daily visibility states by date, remove consecutive duplicates (keeping only state changes), and compute the number of days with final visibility=1 within the first 30 days since creation. The fraction is that count divided by 30 (or by the number of observed days if less than 30).

2. Cohort Aggregation

Group profiles by creation month (cohort). For each cohort, compute the number of profiles, the median fraction, and the 75th and 25th percentiles of the fraction distribution.

3. Handling Incomplete Observation Windows

For profiles created less than 30 days before the analysis date, decide whether to exclude them, use only the observed days (adjusting the denominator), or apply survival analysis techniques. Document the choice and its impact on comparability.

4. Statistical Testing of Trend

Test whether the median fraction decreases with newer cohorts using a non-parametric trend test (e.g., Jonckheere-Terpstra) or by regressing cohort-level medians on cohort order. Consider bootstrapping for confidence intervals and adjust for multiple comparisons if needed.

Key Points to Mention

  • Deduplication of consecutive identical states to avoid overcounting days with visibility=1.
  • Definition of the fraction: days with visibility=1 divided by 30 (or observed days if less than 30).
  • Cohort-level summary statistics: count, median, P75, P25.
  • Handling incomplete windows: exclusion, truncation, or survival analysis, and the trade-offs.
  • Statistical test for trend: Jonckheere-Terpstra, Mann-Kendall, or regression on cohort medians.
  • Potential confounders: seasonality, platform changes, or data quality issues that could affect visibility.

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