Weekly Retention Triangle for TikTok Lite Installs in Pandas

Last updated: November 29, 2026

Quick Overview

Given installs (user_id, install_date) and sessions (user_id, session_date), build a cohort-by-week retention matrix where each cell is the share of a weekly install cohort active in week N after install, blanking out cells that are not fully observed yet.

TikTok
Data Manipulation (SQL/Python)
Data Scientist
TikTok
November 29, 2026
Data Scientist
Take-home Project
Data Manipulation (SQL/Python)
Hard

0

0

0 solved


Given installs (user_id, install_date) and sessions (user_id, session_date), build a cohort-by-week retention matrix where each cell is the share of a weekly install cohort active in week N after install, blanking out cells that are not fully observed yet.

TikTok Lite targets lower-end devices and data-constrained markets, and the team tracks whether new installs stick in the weeks after install. A take-home like this checks correct week indexing from each user's own install date, cohort sizes as denominators, and honest handling of right-censored cells.

What the Interviewer Expects
  • Index weeks from each user's install date, not from the cohort's Monday
  • Use cohort size from installs as the denominator, including users with no sessions
  • Count a user once per week regardless of session count
  • Mask cells whose week has not completed for every user in the cohort
  • Return a tidy matrix that plots directly as a heatmap
Key Topics to Cover
cohort analysis
retention matrix
right censoring
pandas unstack
weekly cohorts
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
  • How would you compare two countries' triangles when their cohort sizes differ by 50x?
  • How would you turn the triangle into a single number for an OKR?
  • Installs that were reinstalls are mixed in. How would you detect and separate them?
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
  • installs(user_id, install_date), first install only.
  • sessions(user_id, session_date), many per day.
  • Week N for a user = days [7N, 7N + 6] after their own install. Cohorts group installs by...
Approach
  1. Assign cohort_week by snapping install date to Monday.
  2. Join sessions to installs, compute week_n = days_since_install // 7, drop negatives (sessions before install are logging noise).
  3. Dis...

Submit Your Answer
Markdown supported