← Snapchat Interview Insights

Snapchat·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Snapchat data scientist interview with a heavy SQL and Python focus, all centered around a user events table. The questions were legitimately hard and the median calculation one in particular made me feel like I had no idea what I was doing for a solid minute.

Questions Asked (4)

Q1

Using a user_events table, write a SQL query to compute 7-day retention (inclusive) for users whose first visit was on 2023-04-01.

Product Analytics & MetricsData Modeling
Author's notes

Went straight for a CTE to isolate first-visit users, then joined back on the same table filtering for events within 7 days.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, identify the cohort of users whose first visit date is exactly 2023-04-01 by finding the minimum event date per user. Then, for each user in that cohort, check if they have at least one event on day 7 (i.e., 2023-04-08) and compute the retention rate as the proportion of retained users. Use a self-join or aggregation with conditional logic to flag retention.

Pro tip: Clarify the definition of '7-day retention (inclusive)' upfront—it typically means the user returned on exactly day 7 after their first visit, not within the first 7 days. Also, mention that you'd handle edge cases like multiple events per day using DISTINCT.

1. Define the cohort

Identify users whose first visit (minimum event date) is 2023-04-01. Use a subquery or CTE to compute MIN(event_date) per user and filter for that date.

2. Determine retention condition

For each user in the cohort, check if they have an event on the 7th day after their first visit (2023-04-08). Use a LEFT JOIN or EXISTS clause to flag retained users.

3. Aggregate and compute rate

Count the number of retained users and divide by the total cohort size. Multiply by 100 for a percentage if needed.

4. Write the SQL query

Combine the steps into a single query using CTEs for readability. Ensure you use DISTINCT to avoid duplicate user counts.

Key Points to Mention

  • Definition of 7-day retention: typically means the user returned on exactly day 7, not within 7 days.
  • Handling multiple events per user per day: use DISTINCT or GROUP BY to avoid double-counting.
  • Cohort definition: first visit date is the minimum event date for each user.
  • Date arithmetic: adding 7 days to the first visit date (e.g., DATE_ADD or + INTERVAL '7 days').
  • SQL techniques: CTEs, subqueries, LEFT JOIN, or EXISTS for retention check.
  • Edge cases: users with no events after first visit, timezone considerations, and data completeness.

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

Q2

Write a SQL query returning the top 3 pages ranked by distinct purchasing users over the last month.

Product Analytics & Metrics
Author's notes

Pretty direct.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the schema and definitions (e.g., what constitutes a 'page', 'purchasing user', and 'last month') before writing the query. Then use a subquery or CTE to count distinct purchasing users per page within the date range, and finally rank and filter to the top 3 pages.

Pro tip: Mention that you would confirm whether 'last month' means the previous calendar month or the last 30 days, and whether to include only completed purchases or also refunds. This shows attention to detail and business context.

1. Clarify requirements and schema

Ask about the table structure, definitions of 'page', 'purchasing user', and the exact time window for 'last month'. Confirm whether to count distinct users who made at least one purchase.

2. Filter events by date and purchase action

Restrict the data to the last month and to rows where a purchase occurred. Ensure you're using the correct timestamp column and handling time zones if necessary.

3. Count distinct purchasing users per page

Group by page and count distinct user IDs to get the number of unique purchasing users for each page.

4. Rank and select top 3 pages

Order the results by the distinct user count in descending order and limit to the top 3 pages. Consider ties and whether to use RANK or DENSE_RANK if needed.

5. Write and validate the SQL query

Compose the final SQL using CTEs or subqueries for readability. Test with sample data or explain how you would validate the results.

Key Points to Mention

  • Use COUNT(DISTINCT user_id) to count unique purchasing users per page.
  • Filter by date range using a WHERE clause on the purchase timestamp (e.g., >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month') AND < DATE_TRUNC('month', CURRENT_DATE)).
  • Group by page identifier and order by the distinct count descending.
  • Limit to 3 results, but discuss handling ties (e.g., using RANK() or DENSE_RANK() in a subquery).
  • Consider performance implications: indexing on date and page columns, and avoiding unnecessary columns in GROUP BY.
  • Mention the importance of defining 'purchasing user' (e.g., users who completed a purchase, not just added to cart).

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

Q3

Find the median number of daily events per active user in April 2023 using SQL.

Product Analytics & MetricsAlgorithms & Data Structures
Author's notes

This one hurt.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the definitions of 'active user' and 'daily events' and confirm the time period (April 2023). Then, write a SQL query that computes the number of events per user per day, filters for active users, and finally calculates the median of those daily counts using a window function or percentile function.

Pro tip: Mention that you would validate the median calculation with a quick sanity check, such as comparing it to the average or examining the distribution, to ensure there are no outliers skewing the result.

1. Clarify definitions and assumptions

Confirm what constitutes an 'active user' (e.g., any user with at least one event in April) and a 'daily event' (e.g., any recorded action). Also confirm the date range and timezone.

2. Aggregate events per user per day

Write a subquery to count the number of events for each user for each day in April 2023, grouping by user_id and date.

3. Filter for active users

If 'active user' is defined as having at least one event in April, the subquery already ensures that. If a different definition (e.g., based on a separate activity table), join or filter accordingly.

4. Compute the median of daily event counts

Use a window function like PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY event_count) or a combination of ROW_NUMBER and COUNT to calculate the median across all user-day combinations.

5. Validate and present results

Check the result for reasonableness, consider edge cases (e.g., users with zero events on some days), and present the final SQL query with clear comments.

Key Points to Mention

  • Definition of 'active user' and 'daily event'
  • Handling of users with zero events on some days (should they be included?)
  • Use of window functions or percentile functions for median calculation
  • Performance considerations for large datasets (e.g., indexing, partitioning)
  • Time zone considerations for date boundaries
  • Potential need to deduplicate events if the event table has duplicates

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

Q4

Given a Pandas DataFrame matching the user_events schema, write Python code to produce an hourly time-series of clicks per page for the past 24 hours.

Product Analytics & MetricsData Modeling
Author's notes

Filter to clicks, filter to last 24 hours using pd.Timestamp.now() minus a timedelta, then groupby page and a floored hourly bucket using dt.floor('H').

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and assumptions (e.g., timestamp column, event type, page identifier). Then filter to the past 24 hours, extract the hour, and group by page and hour to count clicks, ensuring all hours are represented even with zero clicks.

Pro tip: Mention that you would use a timezone-aware timestamp and resample to handle missing hours, and that you'd validate the output by checking the total clicks against the raw data.

1. Clarify schema and assumptions

Confirm the column names (e.g., timestamp, event_type, page_id) and define what constitutes a 'click' (e.g., event_type == 'click'). Also clarify the time range and timezone.

2. Filter and preprocess

Convert the timestamp column to datetime, filter to the last 24 hours relative to the current time (or a given reference time), and extract the hour (e.g., using dt.floor('H')).

3. Aggregate clicks per page per hour

Group by page and hour, count the number of click events, and pivot or unstack to get a time-series per page.

4. Handle missing hours

Reindex the time series to include all 24 hours (e.g., using asfreq or resample) and fill missing counts with 0 to ensure a complete hourly series.

5. Validate and present

Check that the total clicks match the filtered data, and present the resulting DataFrame with hours as rows and pages as columns (or a long format).

Key Points to Mention

  • Timezone handling: ensure timestamps are in a consistent timezone, especially for a global app like Snapchat.
  • Definition of 'click': clarify which event types count as clicks (e.g., 'click', 'tap', etc.).
  • Handling missing hours: use resample or reindex to include all hours, even those with zero clicks.
  • Efficiency: use vectorized operations and avoid loops; consider using groupby with pd.Grouper for time-based grouping.
  • Output format: decide whether to return a wide DataFrame (hours x pages) or long format, and explain the choice.
  • Edge cases: what if there are no clicks for a page? Ensure it still appears with zeros if needed.

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