human
Write me a code to print indices of array elements whose removal makes the sum of odd and even and the other steps required given the following:
Print indices of array elements whose removal makes the sum of odd and even | Function to find indices of array elements whose removal makes the sum of odd and even indexed array elements equal.
Stores size of array.
Store prefix sum of odd index array elements.
Store prefix sum of even index array elements.
Update even [ 0 ].
Traverse the given array.
Update odd [ i ].
Update even [ i ].
If the current index is an even number.
Update even [ i ].
If the current index is an odd number.
Update odd [ i ].
Check if at least one index found or not that satisfies the condition.
Store odd indices sum by removing 0 - th index.
Store even indices sum by removing 0 - th index.
If p and q are equal.
Traverse the array arr.
If i is an even number.
Update p by removing the i - th element.
Update q by removing the i - th element.
Update q by removing the i - th element.
Update p by removing the i - th element.
If odd index values sum is equal to even index values sum.
Set the find variable.
Print the current index.
If no index found.
Print not possible.
Driver Code"
Solution in Python:
assistant
#Here is code to print indices of array elements whose removal makes the sum of odd and even and the other steps required.
 def removeIndicesToMakeSumEqual ( arr ) :
	N = len ( arr ) ;
	odd = [ 0 ] * N ;
	even = [ 0 ] * N ;
	even [ 0 ] = arr [ 0 ] ;
	for i in range ( 1 , N ) :
		odd [ i ] = odd [ i - 1 ] ;
		even [ i ] = even [ i - 1 ] ;
		if ( i % 2 == 0 ) :
			even [ i ] += arr [ i ] ;
		else :
			odd [ i ] += arr [ i ] ;
	find = False ;
	p = odd [ N - 1 ] ;
	q = even [ N - 1 ] - arr [ 0 ] ;
	if ( p == q ) :
		print ( "0 ▁ " ) ;
		find = True ;
	for i in range ( 1 , N ) :
		if ( i % 2 == 0 ) :
			p = even [ N - 1 ] - even [ i - 1 ] - arr [ i ] + odd [ i - 1 ] ;
			q = odd [ N - 1 ] - odd [ i - 1 ] + even [ i - 1 ] ;
		else :
			q = odd [ N - 1 ] - odd [ i - 1 ] - arr [ i ] + even [ i - 1 ] ;
			p = even [ N - 1 ] - even [ i - 1 ] + odd [ i - 1 ] ;
		if ( p == q ) :
			find = True ;
			print ( i , end = " " ) ;
	if ( find == False ) :
		print ( - 1 ) ;
if __name__ == ' _ _ main _ _ ' :
	arr = [ 4 , 1 , 6 , 2 ] ;
	removeIndicesToMakeSumEqual ( arr ) ;