Quant Memo
Coding/●●●●

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 O(n)O(n) total. Recomputing each window's max is O(nk)O(nk); a heap gets O(nlogn)O(n \log n) 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.

More Coding questions