Flag Chat Users Who Exceed a Message Burst Limit
Last updated: November 29, 2026
Quick Overview
Given a time-ordered list of chat messages as (timestamp, user) pairs, return each user who sends more than `limit` messages inside any `window`-second span, along with the timestamp of the message that crossed the limit.
Twitch
November 29, 20260
0
0 solved
Given a time-ordered list of chat messages as (timestamp, user) pairs, return each user who sends more than `limit` messages inside any `window`-second span, along with the timestamp of the message that crossed the limit.
Busy Twitch channels get flooded by copy-paste spam, and a burst detector is the simplest building block behind chat moderation tools. A phone screen version checks that you can keep per-user state, slide a time window correctly, and stop doing work for users who are already flagged.
What the Interviewer Expects
- Keeps a per-user deque of recent timestamps instead of rescanning history
- Evicts timestamps that fall out of the window before counting
- States the boundary rule (is a message exactly `window` seconds old still inside?)
- Stops tracking users once flagged to bound memory
- Gives O(n) total time with an amortized argument
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you bound memory for millions of distinct chatters in one channel?
- How would this change if the limit is on identical messages rather than any message?
- Moderators can set different limits per channel. Where does that config live?
- How would you run this across many chat edge servers handling the same channel?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: messages sorted by timestamp, an integer limit, and a window in seconds. A user violates the rule when more than limit of their messages land in a window, where a message at time t coun...
High-Level Design
Keep a dictionary from user to a deque of their recent message timestamps. For each incoming message, push its timestamp onto that user's deque, pop from the left while the oldest timestamp is outside...