Pick K Non-Overlapping Clip Windows With Peak Chat
Last updated: November 29, 2026
Quick Overview
Given per-second chat message counts for a broadcast, choose at most K non-overlapping windows of exactly L seconds that maximize the total number of messages covered, and return the total and the start second of each window.
Twitch
November 29, 20260
0
0 solved
Given per-second chat message counts for a broadcast, choose at most K non-overlapping windows of exactly L seconds that maximize the total number of messages covered, and return the total and the start second of each window.
Chat velocity is a strong signal for where the exciting moments of a stream are, so it is a natural input for suggesting auto clips or VOD highlights. The interviewer is checking whether you see that greedy picking of the busiest window fails, and whether you can write and reconstruct a clean DP.
What the Interviewer Expects
- Shows a counterexample where greedy picking the max window first is wrong
- Uses prefix sums for O(1) window sums
- Defines dp[k][i] precisely and explains the take or skip transition
- Reconstructs the chosen windows, not just the total
- Discusses reducing memory to O(n) per layer
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 handle K = 3 with n = 10 hours of seconds in a memory-limited service?
- What if windows can have any length between L_min and L_max?
- How would you combine chat velocity with viewer count changes into one score?
- How would you make this incremental while the stream is still live?
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: velocity of length n, window length L, and K. Windows are [s, s+L) and must not overlap. Output the maximum total and the start indices. If L > n, return 0 and no windows....
High-Level Design
Greedy fails: the single busiest window can straddle two good regions and block two windows that together score more (see the trace below). Instead, let dp[k][i] be the best total using only the first...