DiffPush Tier Arrays · Hard O(n) · O(1)
A portfolio system stores a multiplier per period, where a negative multiplier means the position was inverted. The risk desk wants the contiguous run of periods whose multipliers compound to the largest product. A run must be non-empty, and zeros reset the compounding entirely.
Input: An array nums of n integers, one multiplier per period.
Output: The largest product obtainable from a non-empty contiguous run of nums.
1 <= n <= 2 * 10^4-10 <= nums[i] <= 10The answer fits in a 32-bit signed integerInput: {"nums":[2,3,-2,4]}
Output: 6
The opening pair compounds to 6, which beats any run that includes the negative multiplier.
Input: {"nums":[-2,0,-1]}
Output: 0
The zero splits the series, and a single negative multiplier yields less than zero, so nothing beats 0.