Maximize count of pairs whose bitwise XOR is even by replacing such pairs with their Bitwise XOR | Function to maximize the count of pairs with even XOR possible in an array by given operations ; Stores count of odd array elements ; Traverse the array ; If arr [ i ] is odd ; Stores the total number of even pairs ; Input ; Function call to count the number of pairs whose XOR is even
function countPairs ( arr , N ) { let odd = 0 ; for ( let i = 0 ; i < N ; i ++ ) { if ( arr [ i ] & 1 ) odd ++ ; } let ans = ( N - odd + Math . floor ( odd / 2 ) - 1 ) + Math . floor ( odd / 2 ) ; return ans ; } let arr = [ 4 , 6 , 1 , 3 ] ; let N = arr . length ; document . write ( countPairs ( arr , N ) ) ;