Maximum of every sliding window
Asked at HRT, Citadel
Given a price series and window length k, output the maximum of every contiguous window of k prices, the rolling high a market-data system publishes on every tick.
prices = [1, 3, -1, -3, 5, 3, 6, 7], k = 3
-> [3, 3, 5, 5, 6, 7]
Return all window maxima in total. Recomputing each window's max is ; a heap gets with fiddly stale-entry cleanup. The target is the monotonic deque.
Show a hint
If a newer price is higher than an older one, can the older price ever again be a window maximum?
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.