Widest price range in a sliding window
Asked at Jane Street, Optiver
You are watching a price tape and want to know how choppy the market gets. For a fixed window length k, the "range" of a window is its highest price minus its lowest price. Scan every window of exactly k consecutive ticks and report the widest range seen.
prices = [3, 1, 4, 1, 5, 9, 2], k = 3
-> 8 # window [1, 5, 9] has range 9 - 1
Return the maximum of (window max - window min) over all length-k windows. Aim for , recomputing the max and min of each window is .
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.