Maximum Product Subarray

MediumArrays
Next
ArrayDynamic Programming

Find the contiguous, non-empty subarray with the largest product and print that product.

Input

Line 1: n. Line 2: n integers.

Output

Print the maximum subarray product.

Constraints

1 <= n <= 25 -5 <= each value <= 5 The answer fits in a signed 64-bit integer.

Example 1
Input
4
2 3 -2 4
Output
6

The subarray [2, 3] gives 6.

Example 2
Input
3
-2 0 -1
Output
0

The zero splits the array; the best product is 0.

Hints

Maximum Product Subarray - Medium Arrays Problem | Skill Shiksha