Maximum Product Subarray | Returns the product of max product subarray . ; Initializing result ; traversing in current subarray ; updating result every time to keep an eye over the maximum product ; updating the result for ( n - 1 ) th index . ; Driver code
def maxSubarrayProduct ( arr , n ) : NEW_LINE INDENT result = arr [ 0 ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT mul = arr [ i ] NEW_LINE for j in range ( i + 1 , n ) : NEW_LINE INDENT result = max ( result , mul ) NEW_LINE mul *= arr [ j ] NEW_LINE DEDENT result = max ( result , mul ) NEW_LINE DEDENT return result NEW_LINE DEDENT arr = [ 1 , - 2 , - 3 , 0 , 7 , - 8 , - 2 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Maximum ▁ Sub ▁ array ▁ product ▁ is " , maxSubarrayProduct ( arr , n ) ) NEW_LINE