I recognized the sliding window maximum problem immediately and figured the min version would be a straight swap of the comparator.
Use a monotonic deque to maintain indices of potential minimums for the current window, ensuring O(n) time. Handle the initial phase where the window is not full by outputting the running minimum, then transition to the standard sliding window minimum once the window size reaches k.
Pro tip: Clarify the streaming nature: the algorithm should process elements one by one and output the minimum at each step without storing the entire array, which is crucial for large or infinite streams.
Confirm the streaming requirement: process each element as it arrives and output the minimum for the current window (or running minimum if window not full). Discuss edge cases like k=1, k>n, and empty array.
Select a monotonic deque (double-ended queue) to store indices, maintaining increasing order of values. This allows O(1) amortized operations for adding and removing elements.
For each new element: remove indices from the back while the corresponding value is >= the new value; add the new index to the back; remove indices from the front if they are out of the current window; then the front index gives the minimum.
Before the window size reaches k, the minimum is simply the minimum of all elements seen so far. The deque approach naturally handles this if we consider the window as expanding until size k, then sliding.
Explain that each element is added and removed at most once, giving O(n) time and O(k) space. Walk through a small example to verify correctness.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.