← TikTok Interview Insights

TikTok·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

TikTok data scientist interview with a SQL question around identifying repeat advertisers across consecutive weeks. Pretty focused and technical, nothing too wild.

Questions Asked (1)

Q1

Given a table of weekly advertiser ad submissions, write a SQL query to return all advertiser IDs that submitted ads in both Week 1 and Week 2.

Data ModelingProduct Analytics & Metrics
Author's notes

Went with a self-join first, which worked but felt clunky when I looked back at it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the table schema and what 'submitted ads in both weeks' means (e.g., at least one ad per week). Then write a query that filters for Week 1 and Week 2 submissions and finds advertisers present in both sets, using either INTERSECT, INNER JOIN, or GROUP BY with HAVING.

Pro tip: Mention that if the table has a week column, you can use a self-join or GROUP BY with HAVING COUNT(DISTINCT week) = 2; if not, you may need to infer weeks from dates. Also, discuss performance implications and indexing.

1. Understand the table schema

Identify columns like advertiser_id, week (or submission_date), and ad_id. Confirm how weeks are defined (e.g., week number, date range).

2. Clarify the requirement

Ensure 'submitted ads in both weeks' means the advertiser has at least one ad in Week 1 and at least one in Week 2. Consider if duplicates matter.

3. Choose a query strategy

Select an approach: INTERSECT (if supported), INNER JOIN on advertiser_id with week filters, or GROUP BY advertiser_id with HAVING COUNT(DISTINCT week) = 2.

4. Write and validate the query

Write the SQL, ensuring correct filtering and handling of NULLs. Test with sample data to confirm it returns only advertisers in both weeks.

5. Discuss edge cases and performance

Mention handling of advertisers with multiple submissions, missing weeks, and indexing for efficiency.

Key Points to Mention

  • Use of DISTINCT to avoid duplicate advertiser IDs
  • Filtering with WHERE week IN (1,2) before aggregation
  • GROUP BY advertiser_id with HAVING COUNT(DISTINCT week) = 2
  • Alternative: self-join or INTERSECT for set intersection
  • Consideration of NULL values and data types
  • Performance: indexing on (advertiser_id, week) and avoiding unnecessary subqueries

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