Passes Problem
152 Maximum product subarray
def maxProduct(self, nums: List[int]) -> int:
ans = pProduct = nProduct = nums[0]
for n in nums[1:]:
if n < 0:
pProduct, nProduct = nProduct, pProduct
# nProduct is max either current num * previous product or number itself
pProduct = max(n, pProduct*n)
nProduct = min(n, nProduct*n)
ans = max(ans, pProduct)
return ans238. Product of Array Except Self
698. Partition to K Equal Sum Subset
472. Concatenated Words
Last updated