Quant Memo
Coding/●●●●●

Longest stretch of prices within a band

Asked at Jump Trading, Virtu

You want the longest calm stretch of the tape. Given prices and a band width B, find the length of the longest contiguous run in which the maximum price minus the minimum price never exceeds B.

prices = [1, 3, 2, 4, 5], B = 2
-> 3            # the run [1, 3, 2] has range 2

Return the length of the longest run with range at most B. Aim for O(n)O(n).

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions