human
Number of ways to erase exactly one element in the Binary Array to make XOR zero | Function to find the number of ways.
Calculate the number of 1 ' s ▁ and ▁ 0' s.
Considering the 4 cases.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to number of ways to erase exactly one element in the Binary Array to make XOR zero and the other steps required.
 def no_of_ways ( a , n ) :
	count_0 = 0
	count_1 = 0
	for i in range ( 0 , n ) :
		if ( a [ i ] == 0 ) :
			count_0 += 1
		else :
			count_1 += 1
	if ( count_1 % 2 == 0 ) :
		return count_0
	else :
		return count_1
if __name__ == ' _ _ main _ _ ' :
	n = 4
	a1 = [ 1 , 1 , 0 , 0 ]
	print ( no_of_ways ( a1 , n ) )
	n = 5
	a2 = [ 1 , 1 , 1 , 0 , 0 ]
	print ( no_of_ways ( a2 , n ) )
	n = 5
	a3 = [ 1 , 1 , 0 , 0 , 0 ]
	print ( no_of_ways ( a3 , n ) )
	n = 6
	a4 = [ 1 , 1 , 1 , 0 , 0 , 0 ]
	print ( no_of_ways ( a4 , n ) )