human
Find an index such that difference between product of elements before and after it is minimum | Function to return the index i such that the absolute difference between product of elements up to that index and the product of rest of the elements of the array is minimum.
To store the required index.
Prefix product array.
Compute the product array.
Iterate the product array to find the index.
Driver code"
Solution in Python:
 What is a code to find an index such that difference between product of elements before and after it is minimum and the other steps required?
assistant
#Here is code to find an index such that difference between product of elements before and after it is minimum and the other steps required.
 def findIndex ( a , n ) :
	res , min_diff = None , float ( ' inf ' )
	prod = [ None ] * n
	prod [ 0 ] = a [ 0 ]
	for i in range ( 1 , n ) :
		prod [ i ] = prod [ i - 1 ] * a [ i ]
	for i in range ( 0 , n - 1 ) :
		curr_diff = abs ( ( prod [ n - 1 ] // prod [ i ] ) - prod [ i ] )
		if curr_diff < min_diff :
			min_diff = curr_diff
			res = i
	return res
if __name__ == " _ _ main _ _ " :
	arr = [ 3 , 2 , 5 , 7 , 2 , 9 ]
	N = len ( arr )
	print ( findIndex ( arr , N ) )