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
function no_of_ways ( a , n ) { let count_0 = 0 , count_1 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) count_0 ++ ; else count_1 ++ ; } if ( count_1 % 2 == 0 ) return count_0 ; else return count_1 ; } let n = 4 ; let a1 = [ 1 , 1 , 0 , 0 ] ; document . write ( no_of_ways ( a1 , n ) + " " ) ; n = 5 ; let a2 = [ 1 , 1 , 1 , 0 , 0 ] ; document . write ( no_of_ways ( a2 , n ) + " " ) ; n = 5 ; let a3 = [ 1 , 1 , 0 , 0 , 0 ] ; document . write ( no_of_ways ( a3 , n ) + " " ) ; n = 6 ; let a4 = [ 1 , 1 , 1 , 0 , 0 , 0 ] ; document . write ( no_of_ways ( a4 , n ) + " " ) ;