Find the maximum sum pair in an Array with even parity | Javascript implementation to find a pair with even parity and maximum sum ; Function that returns true if count of set bits in given number is even ; Parity will store the count of set bits ; Function to prlet the elements of the array ; Function to remove all the even parity elements from the given array ; Traverse the array ; If the current element has even parity ; Driver Code ; Function Call
let sz = 1e3 ; function isEvenParity ( x ) { let parity = 0 ; while ( x != 0 ) { if ( x % 2 == 1 ) parity ++ ; x = x >> 1 ; } if ( parity % 2 == 0 ) return true ; else return false ; } function prletArray ( arr , len ) { for ( let i = 0 ; i < len ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } function findPairEvenParity ( arr , len ) { let firstMaximum = Number . MIN_VALUE ; let secondMaximum = Number . MIN_VALUE ; for ( let i = 0 ; i < len ; i ++ ) { if ( isEvenParity ( arr [ i ] ) ) { if ( arr [ i ] >= firstMaximum ) { secondMaximum = firstMaximum ; firstMaximum = arr [ i ] ; } else if ( arr [ i ] >= secondMaximum ) { secondMaximum = arr [ i ] ; } } } document . write ( firstMaximum + " " + secondMaximum ) ; } let arr = [ 18 , 15 , 8 , 9 , 14 ] ; let len = arr . length ; findPairEvenParity ( arr , len ) ; ;