Build an N-Day Retention Curve for Amazon Music App Installs in Pandas
Last updated: November 29, 2026
Quick Overview
Given app install records and daily activity records for Amazon Music, write a pandas function that returns day-N retention (active exactly on day N after first install) for N in 1, 7, 14 and 30, counting only users whose day N is observable.
Amazon
November 29, 20260
0
0 solved
Given app install records and daily activity records for Amazon Music, write a pandas function that returns day-N retention (active exactly on day N after first install) for N in 1, 7, 14 and 30, counting only users whose day N is observable.
A pandas exercise in the style of Amazon Devices and Digital analytics take-homes, where retention curves for apps like Amazon Music guide onboarding work. The interviewer checks first-install logic, deduplication, and a right-censored denominator that does not punish recent installers.
What the Interviewer Expects
- Use each user's first install as day 0 and ignore reinstalls
- Deduplicate activity to one row per user per day
- Compute day offsets with datetime arithmetic
- Restrict each day-N denominator to users whose day N is within the data
- Return a tidy table with counts and rates, not just rates
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 you produce an unbounded retention curve (active on day N or later)?
- How would you split the curve by acquisition channel?
- How would you make this efficient for 100 million users?
- How would you add confidence intervals to each point?
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
Inputs:
installs: DataFrame withuser_id,install_date; a user can reinstall, so there may be several rows.activity: DataFrame withuser_id,activity_date, possibly several rows per u...
Approach
- Collapse installs to the first date per user.
- Deduplicate activity per user and day.
- Inner join activity to installs and compute
day_n = activity_date - install_datein days. - For each N,...