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

0

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
gaps and islands
LAG
running SUM grouping
dense grid
disengagement detection
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 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 Problems
Sample 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
  1. Weekly active days per user, densified.
  2. dec = 1 when this week's days are lower than last week's (LAG).
  3. grp = running SUM(1 - dec): it increments on every non-decline row, so a run of d...

Submit Your Answer
Markdown supported