Problems > Maximum Product Subarray

Maximum Product Subarray

Difficulty: 1500 5000 ms 128 MB

dp

Find the maximum product of any non-empty contiguous subarray.

Input: the first line has N; the second line has N integers.

Output: the maximum subarray product.

Constraints:

  • 1 ≤ N ≤ 3000
  • |ai| ≤ 10

Sample Tests

Input 1
4
2 -3 -2 4
Output 1
48
Input 2
3
-2 0 -1
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.