Users Whose Weekly Active Days Declined Four Weeks in a Row
Last updated: November 29, 2026
Quick Overview
Find Facebook users whose number of active days fell week over week for at least four consecutive weeks, and return each qualifying run's starting week, ending week and length, counting weeks with zero activity as zero.
Meta
November 29, 20260
0
0 solved
Find Facebook users whose number of active days fell week over week for at least four consecutive weeks, and return each qualifying run's starting week, ending week and length, counting weeks with zero activity as zero.
Gradual disengagement is harder to catch than sudden churn, so Meta retention teams look for users sliding steadily downward. The interviewer checks a dense user-week grid, LAG to flag declines, and a gaps-and-islands grouping to measure consecutive runs.
What the Interviewer Expects
- Builds a dense user by week grid with zero-filled weeks
- Flags declines with LAG on weekly active days
- Groups consecutive declines with a running sum that increments on non-declines
- Measures run length as the number of declines in each group
- Returns the anchor week and end week for each qualifying run
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 alert only on runs that are still ongoing as of the latest week?
- Users bottoming out at zero cannot decline further. How should that interact with the rule?
- How would you test whether a re-engagement notification sent at the third decline helps?
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
Table: daily_active(user_id, ds). I aggregate to Monday-start weeks and densify from each user's first active week to the last week in the data, so a fully inactive week is 0 and counts as a decline...
Approach
- Weekly active days per user, densified.
dec = 1when this week's days are lower than last week's (LAG).grp = running SUM(1 - dec): it increments on every non-decline row, so a run of d...