Maximize count of pairs whose bitwise XOR is even by replacing such pairs with their Bitwise XOR | Java program to implement the above approach ; 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 ; Driver Code ; Input ; Function call to count the number of pairs whose XOR is even
public class GFG { static int countPairs ( int [ ] arr , int N ) { int odd = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( ( arr [ i ] & 1 ) != 0 ) odd ++ ; } int ans = ( N - odd + odd / 2 - 1 ) + odd / 2 ; return ans ; } public static void main ( String args [ ] ) { int [ ] arr = { 4 , 6 , 1 , 3 } ; int N = arr . length ; System . out . println ( countPairs ( arr , N ) ) ; } }