Stitch Quest Plus Billing Periods Into Tenures Before Counting Churn
Last updated: November 29, 2026
Quick Overview
Meta Quest+ billing data has one row per billing period, with overlaps from plan switches and short gaps from failed renewals. Write Python that merges each user's periods into continuous tenures (treating gaps up to a grace period as continuous) and reports churn count, active status and total tenure days.
Meta
November 29, 20260
0
0 solved
Meta Quest+ billing data has one row per billing period, with overlaps from plan switches and short gaps from failed renewals. Write Python that merges each user's periods into continuous tenures (treating gaps up to a grace period as continuous) and reports churn count, active status and total tenure days.
Reality Labs subscription analytics depends on clean tenure data, and raw billing periods overstate churn when a payment retry or plan change leaves a one-day gap. This screen question is an interval merging problem dressed in a real retention setting; the interviewer checks sorting, merge conditions with a grace window and correct status at the as-of date.
What the Interviewer Expects
- Sort periods by start per user
- Merge on overlap or a gap within the grace window
- Treat open-ended periods as running to the as-of date
- Count churns as tenure ends that are not the current active tenure
- State complexity
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 choose the grace period from data?
- How would you do the same in SQL with window functions?
- What if a period's end date is earlier than its start because of a data bug?
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
Each row is (user_id, start_date, end_date or None), end inclusive. A None end means the current period is still running. as_of is the last day of data. Default grace is 3 days, matching a renewal...
Approach
Group periods per user and sort by start. Walk them, keeping the current merged tenure; if the next period starts on or before current_end + grace, extend the end to the max of both ends, otherwise ...