• 24.8%

https://leetcode.com/problems/maximum-product-subarray/

Find the contiguous subarray within an array (containing at least one number) which has the largest product.

https://discuss.leetcode.com/topic/4417/possibly-simplest-solution-with-o-n-time-complexity

Possibly simplest solution with O(n) time complexity

my code:

#### python

https://discuss.leetcode.com/topic/22001/in-python-can-it-be-more-concise

In Python, can it be more concise?

#### java

https://discuss.leetcode.com/topic/3607/sharing-my-solution-o-1-space-o-n-running-time

Sharing my solution: O(1) space, O(n) running time

Note:

There’s no need to use O(n) space, as all that you need is a minhere and maxhere. (local max and local min), then you can get maxsofar (which is global max) from them.

There’s a chapter in Programming Pearls 2 that discussed the MaxSubArray problem, the idea is similar.

https://discuss.leetcode.com/topic/5161/simple-java-code

Simple Java code

Loop through the array, each time remember the max and min value for the previous product, the most important thing is to update the max and min value: we have to compare among max A[i], min A[i] as well as A[i], since this is product, a negative * negative could be positive.

https://discuss.leetcode.com/topic/3581/share-my-dp-code-that-got-ac

Share my DP code that got AC

f[i] means maximum product that can be achieved ending with i

g[i] means minimum product that can be achieved ending with i