← TikTok Interview Insights

TikTok·Data Scientist·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Sep 2025Remote

Summary

TikTok Data Scientist SQL round, all five questions were analytics-flavored with a strict no-window-functions constraint which honestly tripped me up more than I expected. The schema was straightforward but the edge cases were where they were really testing you.

Questions Asked (5)

Q1

Using only ANSI SQL with no window functions, compute daily active users for each day in a 7-day window, counting distinct users who had a session event on each day.

Product Analytics & MetricsData Modeling
Author's notes

Straightforward GROUP BY on event_date with a WHERE filter and COUNT(DISTINCT user_id).

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and definitions (e.g., session events table with user_id and event_date). Then write a query that filters events to the 7-day window, groups by event_date, and counts distinct user_ids per day. If the window is relative to a specific date, use a subquery or CTE to define the window and join or filter accordingly.

Pro tip: Mention that you would validate the query against a known metric or sample data to ensure correctness, and discuss how you'd handle edge cases like users with multiple sessions in a day or missing dates.

1. Clarify requirements and schema

Confirm the table structure (e.g., events table with user_id, event_type, event_timestamp) and define 'session event' and 'daily active user'. Also clarify the 7-day window (e.g., last 7 days from today or a specific date range).

2. Filter events for the 7-day window

Use a WHERE clause to restrict events to the desired date range, ensuring you only consider session events. If the window is dynamic, use a subquery to calculate the date range.

3. Group by day and count distinct users

Group the filtered events by the date (truncating timestamp to day if needed) and use COUNT(DISTINCT user_id) to compute daily active users for each day.

4. Handle missing dates (optional)

If days with no events should appear with zero DAU, consider left joining a date spine or using a calendar table to ensure all 7 days are represented.

5. Validate and optimize

Check the query against sample data or known metrics. Discuss indexing on event_date and user_id for performance, and consider if the distinct count can be optimized.

Key Points to Mention

  • Definition of daily active user (distinct users with at least one session event per day)
  • Use of COUNT(DISTINCT user_id) to avoid double-counting users with multiple sessions
  • Date truncation or casting timestamp to date to group by day
  • Filtering for session events (e.g., event_type = 'session_start' or similar)
  • Handling of the 7-day window (static vs. relative date range)
  • Potential need for a date spine to include days with zero activity

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

Q2

For users who signed up within a 7-day window, calculate conversion rate by channel, where a converter is any user with at least one purchase within 7 days of their own signup date. Do not double-count users with multiple purchases.

Product Analytics & MetricsA/B Testing & ExperimentationData Modeling
Author's notes

This is where I fumbled a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the definitions: the 7-day signup window, the 7-day conversion window from each user's signup date, and that a converter is a user with at least one purchase within that window. Then, outline a SQL-based approach: filter users by signup date, join with purchases on user_id and purchase_date within 7 days, deduplicate users, and aggregate by channel to compute conversion rate as distinct converters divided by distinct users per channel.

Pro tip: Emphasize that the conversion window is relative to each user's signup date, not a fixed calendar window, and mention that you would validate the query by checking edge cases like users with multiple purchases and users who signed up on the boundary dates.

1. Clarify definitions and assumptions

Confirm the 7-day signup window (e.g., a specific date range) and that the conversion window is 7 days from each user's signup date. Clarify that a converter is a user with at least one purchase in that window, and that users with multiple purchases are counted once.

2. Identify user cohort and channels

Select users who signed up within the specified 7-day window, and extract their acquisition channel (e.g., from a users table). Ensure each user is assigned to exactly one channel.

3. Determine converters

For each user, check if they have at least one purchase within 7 days of their signup date. Use a left join or exists clause to flag converters, ensuring no double-counting of users with multiple purchases.

4. Aggregate by channel and compute conversion rate

Group by channel, count distinct users and distinct converters, then calculate conversion rate as (distinct converters / distinct users) * 100. Present results sorted by channel or conversion rate.

5. Validate and interpret results

Sanity-check the numbers: ensure total users match the cohort size, and consider edge cases like users with no purchases or purchases exactly on day 7. Discuss any limitations, such as incomplete data for recent signups.

Key Points to Mention

  • Use of DISTINCT COUNT to avoid double-counting users with multiple purchases.
  • The conversion window is relative to each user's signup date, not a fixed calendar window.
  • Join condition: purchases where purchase_date >= signup_date AND purchase_date <= signup_date + 7 days.
  • Handling of users with no purchases (they are non-converters but still in the denominator).
  • Potential data issues: users with multiple channels, missing channel data, or timezone considerations.
  • Interpretation: conversion rate by channel helps evaluate marketing effectiveness and guide budget allocation.

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

Q3

Without window functions, compute day-1 retention for each cohort day: among users with a session on day D, what fraction also had a session on day D+1? Return cohort date, retained users, cohort size, and retention rate.

Product Analytics & MetricsData ModelingAlgorithms & Data Structures
Author's notes

Self-join on the events table, matching user_id where one row has event_date = D and the other has event_date = D+1, both session events.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use self-joins or correlated subqueries to compare each user's activity on day D with day D+1, then aggregate by cohort date to compute retention. Alternatively, use GROUP BY with conditional aggregation to count retained users and cohort sizes.

Pro tip: Clarify the definition of 'day-1 retention'—whether it's based on calendar days or 24-hour periods—and mention that you'd handle edge cases like users with multiple sessions or timezone differences.

1. Understand the data and requirements

Identify the session table with user_id and session_date. Clarify that cohort day D is the first day a user appears, and retention is measured on D+1.

2. Identify cohort users per day

For each day D, find all distinct users who had a session. This forms the cohort for that day.

3. Find retained users

For each cohort day D, find users who also had a session on D+1. This can be done with a self-join or EXISTS clause.

4. Aggregate and compute retention

Group by cohort date, count distinct retained users and cohort size, then calculate retention rate as retained/cohort size.

5. Handle edge cases and validate

Consider users with multiple sessions, missing dates, and timezone issues. Validate results with a small sample.

Key Points to Mention

  • Use of self-join or correlated subquery to compare day D and D+1 activity.
  • Definition of cohort: users who had a session on day D, regardless of whether it's their first session.
  • Counting distinct users to avoid duplicates from multiple sessions.
  • Handling of missing dates or users with no activity on D+1.
  • Performance considerations: indexing on user_id and session_date.
  • Alternative approach using GROUP BY with conditional aggregation (e.g., SUM(CASE WHEN ...)).

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

Q4

For all users, return each user's first purchase date and their total lifetime revenue, using only aggregates and GROUP BY. No window functions.

Data ModelingProduct Analytics & Metrics
Author's notes

MIN(CASE WHEN event_type = 'purchase' THEN event_date END) for first purchase date, SUM(amount) or COALESCE(SUM(amount), 0) for lifetime revenue.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the schema and definitions: identify the user, purchase date, and revenue columns, and confirm that 'first purchase date' means the minimum purchase date per user. Then write a single query that groups by user and computes MIN(purchase_date) and SUM(revenue), ensuring you handle potential NULLs or duplicate transactions appropriately.

Pro tip: Mention that while window functions are prohibited, you can still achieve the result with a self-join or subquery if needed, but a simple GROUP BY is sufficient here. Also, note that in a real interview, you'd validate the output against a sample to catch edge cases like users with no purchases.

1. Clarify requirements and schema

Ask clarifying questions about the table structure, column names, and definitions (e.g., what constitutes a purchase, how revenue is calculated). Confirm that 'first purchase date' is the earliest date per user and 'total lifetime revenue' is the sum of all purchases.

2. Identify necessary columns and tables

Determine which table(s) contain user IDs, purchase dates, and revenue amounts. If multiple tables are involved, plan the join logic to combine them before aggregation.

3. Write the aggregation query

Use a GROUP BY on the user ID column and apply MIN(purchase_date) for the first purchase date and SUM(revenue) for total lifetime revenue. Ensure you handle NULLs appropriately (e.g., exclude NULL revenues or treat as zero).

4. Validate and consider edge cases

Check for users with no purchases (they might be excluded or included with NULL/0 values depending on requirements). Also consider time zones, date formats, and whether revenue should be summed per transaction or per user.

5. Optimize and explain

Discuss potential performance considerations (e.g., indexing on user_id and purchase_date) and explain why this approach is efficient without window functions.

Key Points to Mention

  • Use of MIN() and SUM() aggregate functions with GROUP BY on user ID.
  • Handling of NULL values in revenue or purchase date columns.
  • Definition of 'first purchase date' as the minimum date per user.
  • Potential need to filter out test users or invalid transactions.
  • Consideration of time zones and date truncation if applicable.
  • Performance implications and indexing strategies for large datasets.

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

Q5

Identify the single top channel by total purchase revenue for a given 7-day period, breaking ties by lexicographically smallest channel name. Return one row with channel and total revenue.

Product Analytics & MetricsData ModelingAlgorithms & Data Structures
Author's notes

No window functions makes this annoying.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First clarify the schema and definitions (e.g., purchase revenue, channel, date range). Then write a SQL query that filters the 7-day period, aggregates revenue per channel, and selects the top channel using ORDER BY total_revenue DESC, channel ASC with LIMIT 1. If discussing algorithms, explain that sorting or a single-pass max with tie-breaking achieves O(n) time.

Pro tip: Explicitly state your assumptions about the data model and edge cases (e.g., ties, nulls, timezone) before writing the query—this shows you think like a data scientist who cares about correctness, not just syntax.

1. Clarify requirements and schema

Ask about the table structure, column names, definition of 'purchase revenue', and how the 7-day period is defined (inclusive dates, timezone). Confirm tie-breaking rule: lexicographically smallest channel name.

2. Plan the aggregation and selection logic

Decide to group by channel, sum revenue, then order by total revenue descending and channel ascending, and limit to 1 row. Consider if you need to handle ties explicitly or if ORDER BY with LIMIT suffices.

3. Write the SQL query

Construct a query like: SELECT channel, SUM(revenue) AS total_revenue FROM purchases WHERE date BETWEEN 'start' AND 'end' GROUP BY channel ORDER BY total_revenue DESC, channel ASC LIMIT 1;

4. Discuss algorithmic considerations

If asked about implementation without SQL, explain that you can scan the data once, maintain a running max per channel, and apply tie-breaking. Mention time complexity O(n) and space O(k) for k channels.

5. Validate and handle edge cases

Mention testing with ties, empty results, and null channels. Ensure the query returns exactly one row and that tie-breaking is correctly applied.

Key Points to Mention

  • Use of GROUP BY and SUM for aggregation
  • ORDER BY total_revenue DESC, channel ASC for tie-breaking
  • LIMIT 1 to return a single row
  • Date filtering for the 7-day period (inclusive/exclusive)
  • Handling of ties and lexicographic ordering
  • Time complexity and efficiency for large datasets

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