values. Choose a non-empty stretch of consecutive elements whose product is as large as possible and return that product.
Keep in mind that values may be negative or zero.values=[-3, 2, -4, 0, 5] → 24
The stretch [-3, 2, -4] gives (-3) · 2 · (-4) = 24, since the two negatives cancel out. Past the zero the best is just 5.
values=[-5, 0, -2] → 0
The stretches [-5, 0, -2] and [0] give 0, and -5 or -2 alone are worse. -5 and -2 are not adjacent, so they cannot be multiplied on their own.
values=[-7] → -7
values=[-3, 2, -4, 0, 5]
24
Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.