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
Coding & Algorithms
Software Engineer
TikTok
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
monotonic queue
sliding window maximum
deque
streaming
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 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 Problems
Sample 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...


Submit Your Answer
Markdown supported