Smallest index that splits an array into two subarrays with equal product | Function to find the smallest index that splits the array into two subarrays with equal product ; Stores the product of the array ; Traverse the given array ; Stores the product of left and the right subarrays ; Traverse the given array ; Update the products ; Check if product is equal ; Print resultant index ; If no partition exists , then print - 1. ; Driver Code
def prodEquilibrium ( arr , N ) : NEW_LINE INDENT product = 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT product *= arr [ i ] NEW_LINE DEDENT left = 1 NEW_LINE right = product NEW_LINE for i in range ( N ) : NEW_LINE INDENT left = left * arr [ i ] NEW_LINE right = right // arr [ i ] NEW_LINE if ( left == right ) : NEW_LINE INDENT print ( i + 1 ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( - 1 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 3 , 2 , 1 ] NEW_LINE N = len ( arr ) NEW_LINE prodEquilibrium ( arr , N ) NEW_LINE DEDENT