Maximum Product Run
Return the largest product of a non-empty contiguous subarray of nums.
Requirements
- : track both the maximum and minimum product ending at each position, because a negative number swaps them.
Examples
EXAMPLE WALKTHROUGHskip the negative
A guided view of the published example, not a trace of your code.
INPUT
[[2,3,-2,4]]TASKmax_product_run()
EXPECTED OUTPUT
6Start with the input values shown in this example.
Example 1 of 3
Input: nums = [2,3,-2,4]
Output: 6
Explanation: skip the negative
Input: nums = [-2,0,-1]
Output: 0
Explanation: zero
Input: nums = [-2,3,-4]
Output: 24
Explanation: two negatives
Hint 1
At each step the new max is the largest of x, x * max, x * min.
Hint 2
Zeros reset both products.