Quant Memo
Coding/●●●●●

Best contiguous stretch of daily returns

Given a strategy's daily PnL (positive and negative), find the single contiguous stretch of days with the largest total. You must pick consecutive days, no cherry-picking.

returns = [3, -4, 5, -1, 2, -6, 4]
-> 6        # the run [5, -1, 2]

Return the maximum sum of any contiguous subarray in O(n) time and O(1) space.

Your answer

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

More Coding questions