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
def no_of_ways ( a , n ) : NEW_LINE INDENT count_0 = 0 NEW_LINE count_1 = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( a [ i ] == 0 ) : NEW_LINE INDENT count_0 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT count_1 += 1 NEW_LINE DEDENT DEDENT if ( count_1 % 2 == 0 ) : NEW_LINE INDENT return count_0 NEW_LINE DEDENT else : NEW_LINE INDENT return count_1 NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 4 NEW_LINE a1 = [ 1 , 1 , 0 , 0 ] NEW_LINE print ( no_of_ways ( a1 , n ) ) NEW_LINE n = 5 NEW_LINE a2 = [ 1 , 1 , 1 , 0 , 0 ] NEW_LINE print ( no_of_ways ( a2 , n ) ) NEW_LINE n = 5 NEW_LINE a3 = [ 1 , 1 , 0 , 0 , 0 ] NEW_LINE print ( no_of_ways ( a3 , n ) ) NEW_LINE n = 6 NEW_LINE a4 = [ 1 , 1 , 1 , 0 , 0 , 0 ] NEW_LINE print ( no_of_ways ( a4 , n ) ) NEW_LINE DEDENT