Peak Viewer Count in Every Rolling Window of K Minutes
Last updated: November 29, 2026
Quick Overview
Given a per-minute series of concurrent viewer counts for a LIVE broadcast and a window size k, return the maximum viewer count in each consecutive window of k minutes.
TikTok
November 29, 20260
0
0 solved
Given a per-minute series of concurrent viewer counts for a LIVE broadcast and a window size k, return the maximum viewer count in each consecutive window of k minutes.
Creator dashboards on TikTok LIVE show rolling peaks, and this is the monotonic deque question in a product setting. Interviewers want the O(n) deque solution, the invariant behind it, and the expiry check done in the right order.
What the Interviewer Expects
- Starts from the O(nk) baseline and the O(n log k) heap alternative
- Maintains a deque of indices with decreasing values
- Expires the front when it leaves the window
- Emits output only once the first full window exists
- Explains amortized O(n)
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 compute rolling minimums and maximums together for a volatility metric?
- Data is a stream of unknown length; what does the API look like?
- How would you handle missing minutes in the series?
- How would you compute this across 100k concurrent streams in a Flink job?
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: list of non-negative integers and window size k >= 1. Output: n - k + 1 maxima, or empty if n < k. Ties are fine either way since we output values....
High-Level Design
Keep a deque of indices whose values are strictly decreasing from front to back. When minute i arrives, pop from the back every index whose value is at most the new one: those minutes can never be a w...