Trending Emotes Over a Rolling Time Window
Last updated: November 29, 2026
Quick Overview
Design a class that records emote uses as (timestamp, emote) events and answers `top_k(now, k)`, the k most used emotes in the last `window` seconds, with ties broken alphabetically.
Twitch
November 29, 20260
0
0 solved
Design a class that records emote uses as (timestamp, emote) events and answers `top_k(now, k)`, the k most used emotes in the last `window` seconds, with ties broken alphabetically.
Emote usage spikes are how chat reacts to a big moment on stream, and a rolling top-k feeds features like highlighted emotes and clip suggestions. The interviewer wants a correct eviction story, a sensible split between update cost and query cost, and a conversation about approximation at Twitch scale.
What the Interviewer Expects
- Stores events in a deque and evicts expired ones on both writes and reads
- Maintains live counts in a hash map so eviction is O(1) per event
- Uses a heap or partial sort for top-k instead of sorting everything
- Deletes zero counts so the map does not grow
- Discusses Count-Min Sketch or bucketed counters for very high volume
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
- A channel with 500k viewers produces 50k emote events per second. What breaks first?
- How would you change this to time-bucketed counts to cap memory?
- How would you merge top-k results from many chat shards?
- How would you detect a sudden spike rather than plain volume?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
record(ts, emote) with non-decreasing timestamps, and top_k(now, k) returning a list of (emote, count) for events with ts > now - window. Ties go to the alphabetically smaller emote so the outpu...
High-Level Design
Two structures: a deque of raw events in arrival order, and a Counter of live counts. Eviction pops from the left of the deque while the oldest event is out of the window and decrements its count. A q...