human
Find minimum operations needed to make an Array beautiful | Function to find minimum operations required to make array beautiful.
counting consecutive zeros ..
check that start and end are same.
check is zero and one are equal.
Driver code"
How can the above be solved in Python?
 Give me a code to find minimum operations needed to make an Array beautiful and the other steps required?
assistant
#Here is code to find minimum operations needed to make an Array beautiful and the other steps required.
 def minOperations ( A , n ) :
	if n & 1 :
		return - 1
	zeros , consZeros , ones = 0 , 0 , 0
	for i in range ( n ) :
		if A [ i ] :
			zeros += 1
		else :
			ones += 1
		if ( i + 1 < n ) :
			if A [ i ] == 0 and A [ i + 1 ] == 0 :
				consZeros += 1
	if A [ 0 ] == A [ n - 1 ] and A [ 0 ] == 0 :
		consZeros += 1
	if zeros == ones :
		return consZeros
	else :
		return - 1
if __name__ == " _ _ main _ _ " :
	A = [ 1 , 1 , 0 , 0 ]
	n = len ( A )
	print ( minOperations ( A , n ) )