Kaplan-Meier Survival Curve for Meta Quest Plus Subscribers in Python
Last updated: November 29, 2026
Quick Overview
Given Meta Quest+ subscriptions with start dates and optional cancellation dates, write Python that computes the Kaplan-Meier survival curve in days since start, correctly treating still-active subscribers as censored, and returns the survival probability at any day.
Meta
November 29, 20260
0
0 solved
Given Meta Quest+ subscriptions with start dates and optional cancellation dates, write Python that computes the Kaplan-Meier survival curve in days since start, correctly treating still-active subscribers as censored, and returns the survival probability at any day.
Subscription products at Meta Reality Labs have cohorts of very different ages, so naive churn rates understate churn for young cohorts. This onsite question checks whether a candidate understands censoring and can implement the product-limit estimator from scratch with correct tie handling.
What the Interviewer Expects
- Explain why active subscribers are censored, not survivors forever
- Compute durations relative to each subscriber's own start
- Remove both churned and censored users from the risk set after each time
- Handle ties between churn and censoring at the same day correctly
- Provide a lookup for survival at arbitrary days
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 add a confidence band using Greenwood's formula?
- How would you compare survival for annual versus monthly plans?
- What if a user cancels and resubscribes later?
- Why not just compute the share of all subscribers who cancelled within 30 days?
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
Input rows: (user_id, start_date, cancel_date or None), plus as_of (last day of data). A cancel after as_of is treated as not yet observed. Duration is days from start to cancel, or start to `as...
Approach
Kaplan-Meier: at each day with churns and subscribers still at risk, . Count churns and censorings per duration, walk durations in order, mult...