Detect Comment Bursts of Five Comments Within Sixty Seconds
Last updated: November 29, 2026
Quick Overview
Find accounts that posted at least five comments within any sixty-second span, and for each such account return the number of bursts and the time the first burst completed. Use the comments table only, with no self-join.
Meta
November 29, 20260
0
0 solved
Find accounts that posted at least five comments within any sixty-second span, and for each such account return the number of bursts and the time the first burst completed. Use the comments table only, with no self-join.
Comment spam and scripted engagement are a constant integrity problem across Facebook and Instagram, and Meta interviewers use burst detection to see whether you know the LAG-with-offset trick. Checking each comment against the one four positions earlier replaces an expensive self-join on time ranges.
What the Interviewer Expects
- Recognizes that five comments within 60 seconds means the current comment and the one four rows earlier are within 60 seconds
- Uses LAG(created_at, 4) partitioned by user
- Orders with a tie-break for identical timestamps
- Explains that overlapping windows each count, and how to dedupe if needed
- Compares cost against a range self-join
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 count non-overlapping bursts only?
- How would you parameterize the rule for N comments in T seconds and choose N and T from data?
- How would you exclude legitimate rapid replies inside a live video chat?
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: comments(comment_id, user_id, target_id, created_at). I will treat timestamps at second precision and order ties by comment_id. 'Within sixty seconds' means the first and fifth comment are ...
Approach
Sort a user's comments by time. Any five consecutive comments form the tightest possible group of five, so a burst exists ending at comment i exactly when created_at[i] - created_at[i-4] <= 60s. `LA...