I knew the monotonic deque approach for the standard sliding window max/min problem.
Use a monotonic deque to maintain indices of potential minimums in the current window. For the first k-1 elements, output the minimum so far; once the window is full, slide it by removing outdated indices and maintaining the deque property to output the window minimum in O(1) amortized time.
Pro tip: Clarify the streaming aspect: the algorithm should process elements one by one, outputting after each element. Emphasize that the deque stores indices, not values, to efficiently check if the front is out of the window.
Restate the problem: for each index i, output the minimum of the last min(i+1, k) elements. Consider edge cases like k=1, k>n, and empty array.
Explain that a monotonic deque (double-ended queue) is ideal because it allows O(1) amortized insertion and removal while maintaining the minimum at the front.
For each element, remove indices from the back while the corresponding values are >= current, then add current index. Remove front if it's out of the window. Output the front's value.
For the first k-1 elements, the window isn't full, so the minimum is simply the minimum of all elements seen so far, which is the front of the deque.
Each element is added and removed at most once, so 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.