Count pairs from given array with Bitwise OR equal to K | Function that counts the pairs from the array whose Bitwise OR is K ; Stores the required count of pairs ; Generate all possible pairs ; Perform OR operation ; If Bitwise OR is equal to K , increment count ; Prlet the total count ; Driver Code ; Function Call
function countPairs ( arr , k , size ) { let count = 0 , x ; for ( let i = 0 ; i < size - 1 ; i ++ ) { for ( let j = i + 1 ; j < size ; j ++ ) { x = arr [ i ] | arr [ j ] ; if ( x == k ) count ++ ; } } document . write ( count ) ; } let arr = [ 2 , 38 , 44 , 29 , 62 ] ; let K = 46 ; let N = arr . length ; countPairs ( arr , K , N ) ;