Weekly Install Cohort D1 and D7 Retention for CapCut in Pandas
Last updated: November 29, 2026
Quick Overview
Using pandas, compute D1 and D7 retention for each weekly install cohort of CapCut users from an installs table that contains reinstalls and an activity log, without counting users whose day N has not happened yet as churned.
ByteDance
November 29, 20260
0
0 solved
Using pandas, compute D1 and D7 retention for each weekly install cohort of CapCut users from an installs table that contains reinstalls and an activity log, without counting users whose day N has not happened yet as churned.
ByteDance growth and product analytics teams for apps like CapCut and Lemon8 live on cohort retention, so data scientist screens often include a pandas exercise on it. The interviewer looks for a clean definition of the cohort, correct handling of reinstalls, and a right-censoring rule for recent cohorts.
What the Interviewer Expects
- Defines the cohort by each user's first install, not every install row
- Defines Dn retention as active on exactly install day plus n, and says so
- Deduplicates activity to one row per user per day before counting
- Excludes users from the Dn denominator until day n has elapsed as of the report date
- Produces a tidy table with cohort size and both rates, using vectorized pandas
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would the numbers change if D7 meant active on any day from 1 to 7 (rolling retention)?
- Which time zone should define a day for a global app, and what breaks if you use UTC?
- How would you compute this for 500 million users when it no longer fits in memory?
- How would you tell whether a dip in one cohort is a product change or a marketing mix change?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
installs(user_id, install_ts) can have several rows per user because of reinstalls or device changes; activity(user_id, event_ts) has many events per day. I confirm: the cohort is the Monday-start...
Approach
- Group installs by user and take the minimum day, then derive
cohort_weekby subtracting the weekday. - Reduce activity to distinct (user, day) pairs, inner join to first installs, compute `day_n...