Peak CPU Load in Every Sliding Window of K Samples
Last updated: November 29, 2026
Quick Overview
Given a sequence of CPU load samples and a window size k, return the maximum load in every contiguous window of k samples, in O(n) total time.
0
0
0 solved
Given a sequence of CPU load samples and a window size k, return the maximum load in every contiguous window of k samples, in O(n) total time.
Framed around Borg-style cluster monitoring where alerts fire on rolling peaks, this is the monotonic deque question. Google interviewers push past the heap solution to the linear one and expect a clear argument for why each index enters and leaves the deque once.
What the Interviewer Expects
- Starts from the O(nk) brute force and the O(n log k) heap with lazy deletion
- Maintains a deque of indices with strictly decreasing values
- Evicts indices that fall out of the window from the front
- Drops dominated smaller values from the back
- Proves O(n) amortized
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
- Support both max and min of the window at the same time.
- The window is defined by time (last 60 seconds) with irregular sample times.
- Compute the maximum over windows in a distributed stream split across machines.
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
aof n numbers, integer k with 1 at most k at most n. - Output: list of n - k + 1 maxima, one per window start.
- Target O(n) time and O(k) extra space....
High-Level Design
Keep a deque of indices whose values are strictly decreasing from front to back; the front is always the max of the current window. For each new index i: pop from the back every index whose value is a...