Group Push Notifications into Digests Anchored at the First Send
Last updated: November 29, 2026
Quick Overview
Given a log of push notifications queued per user, group them into digests where each digest opens at the first pending notification and absorbs everything queued within the next 60 minutes of that opening notification. Return each digest's start time, size and notification ids.
Meta
November 29, 20260
0
0 solved
Given a log of push notifications queued per user, group them into digests where each digest opens at the first pending notification and absorbs everything queued within the next 60 minutes of that opening notification. Return each digest's start time, size and notification ids.
Notification volume is tightly managed at Meta, and batching rules like this sit behind digest pushes and emails. The interviewer uses it to see whether you recognize that an anchored window is not expressible with a simple LAG gap rule and requires a sequential pass.
What the Interviewer Expects
- Distinguishes an anchored window from a gap-based session (time since previous event)
- Sorts each user's notifications by time with a stable tie-break
- Walks the sequence once, opening a new digest when a notification falls outside the anchor window
- Flushes the final open digest
- Explains why plain window functions cannot express this without recursion
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 express this in SQL? What does a recursive CTE look like and what does it cost?
- How would you add a cap of at most five notifications per digest?
- How would this run in a streaming system where notifications arrive out of order by up to two minutes?
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
Input rows: (user_id, sent_at, notif_id). Window: 60 minutes, half-open, so a notification exactly 60 minutes after the anchor starts a new digest. Ties on sent_at are ordered by notif_id....
Approach
A gap rule (new group when the gap since the previous event exceeds 60 minutes) can be done with LAG and a running sum. This rule is different: the window is measured from the digest's first event...