Clean Experiment Exposures Before Comparing Watch Time by Arm

Last updated: November 29, 2026

Quick Overview

Given an exposures log that can contain repeated exposures and users who appear in both arms, compute average post-exposure watch minutes per user for control and treatment after removing contaminated users, and report the contamination rate.

TikTok
Data Manipulation (SQL/Python)
Data Scientist
TikTok
November 29, 2026
Data Scientist
Onsite
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given an exposures log that can contain repeated exposures and users who appear in both arms, compute average post-exposure watch minutes per user for control and treatment after removing contaminated users, and report the contamination rate.

TikTok runs a very large number of concurrent experiments through its internal platform, and analysts frequently hand-check raw exposure logs when a result looks odd. The interviewer is checking whether you deduplicate exposures to one row per user, detect cross-arm users, and only count outcomes after first exposure.

What the Interviewer Expects
  • Collapse repeated exposures to the first exposure per user
  • Detect users with more than one variant and remove or report them
  • Measure outcomes only from first exposure onward
  • Keep exposed users with zero watch time via a LEFT JOIN
  • Report contamination rate and why a high rate invalidates the test
Key Topics to Cover
experiment hygiene
deduplication
joins
exposure logging
sample ratio mismatch
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • Contamination is 5% and concentrated in treatment. What does that suggest?
  • Why can dropping contaminated users bias the result, and what is the alternative?
  • How would you also run a sample ratio mismatch check in the same query?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data
  • exposures(user_id, experiment_id, variant, exposed_at), logged each time the feature renders, so many rows per user.
  • daily_watch(user_id, ds, watch_minutes).
  • Contaminated user = more than on...
Approach
  1. One row per user: first exposure date, count of distinct variants.
  2. Keep users with exactly one variant.
  3. LEFT JOIN watch rows on or after first exposure, so a user who was exposed and then sto...

Submit Your Answer
Markdown supported