Best compounding streak with sign flips
Asked at Optiver
Treat each day's value as a multiplicative growth factor (so returns compound). Find the contiguous run of days with the largest product. Negatives make this subtle: two negatives can multiply into a large positive.
factors = [2, -3, -2, 4]
-> 48 # 2 * -3 * -2 * 4
Return the maximum product 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.