Negative numbers flip max/min products, so track both.
Scan array maintaining:
curMax = max product ending herecurMin = min product ending here
If x < 0, swap curMax and curMin, then update.Any max product ending at i is either x alone or extends a previous product; negative values can turn a previous minimum into a maximum.
Negative numbers flip max/min products, so track both.
Scan array maintaining:
curMax = max product ending herecurMin = min product ending here
If x < 0, swap curMax and curMin, then update.Any max product ending at i is either x alone or extends a previous product; negative values can turn a previous minimum into a maximum.