(arr)
arr is list of positive/negative numbers
arr is list of positive/negative numbers
arr is list of positive / negative numbers
def subarray_with_max_product(arr):
    ''' arr is list of positive/negative numbers '''
    l = len(arr)
    product_so_far = max_product_end = 1
    max_start_i = 0
    so_far_start_i = so_far_end_i = 0
    all_negative_flag = True

    for i in range(l):
        max_product_end *= arr[i]
        if arr[i] > 0:
            all_negative_flag = False

        if max_product_end <= 0:
            max_product_end = arr[i]
            max_start_i = i

        if product_so_far <= max_product_end:
            product_so_far = max_product_end
            so_far_end_i = i
            so_far_start_i = max_start_i

    if all_negative_flag:
        print("max_product_so_far: %s, %s" %
              (reduce(lambda x, y: x * y, arr), arr))
    else:
        print("max_product_so_far: %s, %s" %
              (product_so_far, arr[so_far_start_i:so_far_end_i + 1]))
def subarray_with_max_product ( arr ) : l = len ( arr ) product_so_far = max_product_end = 1 max_start_i = 0 so_far_start_i = so_far_end_i = 0 all_negative_flag = True for i in range ( l ) : max_product_end *= arr [ i ] if arr [ i ] > 0 : all_negative_flag = False if max_product_end <= 0 : max_product_end = arr [ i ] max_start_i = i if product_so_far <= max_product_end : product_so_far = max_product_end so_far_end_i = i so_far_start_i = max_start_i if all_negative_flag : print ( "max_product_so_far: %s, %s" % ( reduce ( lambda x , y : x * y , arr ) , arr ) ) else : print ( "max_product_so_far: %s, %s" % ( product_so_far , arr [ so_far_start_i : so_far_end_i + 1 ] ) )