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
Coding & Algorithms
Software Engineer
Twitch
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
Sliding window
Deque
Hash map
Rate detection
Amortized analysis
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported

Related Questions