Flag Users Whose Time Spent Fell Below Half Their 28-Day Average
Last updated: November 29, 2026
Quick Overview
For each user and day, compare that day's Facebook app time spent with the user's average over the previous 28 days (not including today), and flag days where today is below 50 percent of that baseline. Only flag users with at least 14 active days in the baseline window.
Meta
November 29, 20260
0
0 solved
For each user and day, compare that day's Facebook app time spent with the user's average over the previous 28 days (not including today), and flag days where today is below 50 percent of that baseline. Only flag users with at least 14 active days in the baseline window.
Early churn signals feed retention efforts across the Facebook app, and a personal-baseline comparison is a common Meta onsite query. The interviewer looks for a frame that excludes the current row, zero-filled inactive days, and a minimum-history guard.
What the Interviewer Expects
- Builds a per-user daily series that includes zero-minute days
- Uses ROWS BETWEEN 28 PRECEDING AND 1 PRECEDING to exclude today
- Counts active days in the baseline window with a conditional window sum
- Applies both the 50 percent rule and the minimum-history rule
- Explains why including today in the baseline biases the flag
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 turn the flag into a daily count of at-risk users by country?
- Would a median baseline be more robust than a mean? How would you compute a rolling median?
- How would you account for weekly seasonality, for example comparing Saturday only to prior Saturdays?
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: user_daily_time(user_id, ds, minutes), one row per user per active day. Inactive days have no row. I will build each user's series from their first active day to the analysis end date, fillin...
Approach
- Per-user spine from first active day to max date, left joined to minutes with zeros.
AVG(minutes)over the 28 preceding rows, excluding the current row.- `SUM(CASE WHEN minutes > 0 THEN 1 EL...