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
Data Manipulation (SQL/Python)
Data Scientist
Meta
November 29, 2026
Data Scientist
Onsite
Data Manipulation (SQL/Python)
Hard

0

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
Kaplan-Meier
right censoring
survival analysis
risk set
subscription churn
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 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 Problems
Sample 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 tt with dtd_t churns and ntn_t subscribers still at risk, S(t)=∏ti≤t(1−di/ni)S(t) = \prod_{t_i \le t} (1 - d_i / n_i). Count churns and censorings per duration, walk durations in order, mult...


Submit Your Answer
Markdown supported