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

For example, given the array [2,3,-2,4],
the contiguous subarray [2,3] has the largest product = 6.
"""


def max_subarray_prod(arr):
    best = float('-inf')
    pos, neg = 1, 1
    for el in arr:
        pos, neg = max(el, pos * el, neg * el), min(el, pos * el, neg * el)
        best = max(best, pos, neg)

    return best


if __name__ == '__main__':
    print max_subarray_prod([-4, -3])
