Created
October 31, 2017 11:52
-
-
Save cbdavide/73be7fb0bf6585d34980ea2527e18062 to your computer and use it in GitHub Desktop.
Maximum subarray product.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''''Maximum Subarray Problem - Extended Kadane | |
Source: https://www.quora.com/How-do-I-solve-maximum-product-subarray-problems | |
''' | |
def max_product(A): | |
maxG, maxC, minC = A[0], A[0], A[0] | |
for num in A: | |
temp = maxC | |
maxC = max([num, temp * num, minC * num]) | |
minC = min([num, temp * num, minC * num]) | |
maxG = max([maxG, maxC, minC]) | |
print(maxG) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment