Report Peak CPU Load Over Every Sliding Time Window
Last updated: November 29, 2026
Quick Overview
Given per-second CPU utilization samples for a virtual machine and a window size k, return the maximum utilization in every contiguous window of k samples in linear time.
Microsoft
November 29, 20260
0
0 solved
Given per-second CPU utilization samples for a virtual machine and a window size k, return the maximum utilization in every contiguous window of k samples in linear time.
Autoscale rules in Azure Virtual Machine Scale Sets trigger on peak or average load over a trailing window, which makes this problem a natural fit for Microsoft. The interviewer expects a heap solution first and then looks for the monotonic deque, with a convincing argument for why each element is processed a constant number of times.
What the Interviewer Expects
- Starts from brute force O(n * k) and a heap O(n log n)
- Arrives at a monotonic decreasing deque of indices
- Explains why dominated elements can be discarded forever
- Proves amortized O(n) by counting pushes and pops
- Handles equal values and window boundaries correctly
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
- Return the minimum and maximum together for each window.
- How would you answer arbitrary range-max queries on historical data?
- The window is time-based and samples arrive irregularly: what changes?
- How would you compute this in a streaming system across thousands of VMs?
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: a list of numbers and window size k with 1 <= k <= n. Output: n - k + 1 maxima, one per window ending at index k - 1 onward. Target O(n)....
High-Level Design
Brute force recomputes each window in O(k). A max-heap with lazy expiry gets O(n log n). The linear solution relies on dominance: if a newer sample is greater than or equal to an older one, the older ...