Quant Memo
Coding/●●●●

Longest balanced run of ups and downs

Asked at Two Sigma, Jane Street

Each tick moved the price up ("U") or down ("D"). Find the length of the longest contiguous stretch of ticks containing equally many ups and downs.

moves = "UUDD"
-> 4            # two ups, two downs across the whole string

Return the length of the longest balanced substring. 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