Count of even set bits between XOR of two arrays | Function that count the XOR of B with all the element in A having even set bit ; Count the set bits in A [ i ] ; check for even or Odd ; To store the count of element for B such that XOR with all the element in A having even set bit ; Count set bit for B [ i ] ; check for Even or Odd ; Driver Code
def countEvenBit ( A , B , n , m ) : NEW_LINE INDENT i , j , cntOdd = 0 , 0 , 0 NEW_LINE cntEven = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT x = bin ( A [ i ] ) [ 2 : ] . count ( '1' ) NEW_LINE if ( x & 1 ) : NEW_LINE INDENT cntEven += 1 NEW_LINE DEDENT else : NEW_LINE INDENT cntOdd += 1 NEW_LINE DEDENT DEDENT CountB = [ 0 ] * m NEW_LINE for i in range ( m ) : NEW_LINE INDENT x = bin ( B [ i ] ) [ 2 : ] . count ( '1' ) NEW_LINE if ( x & 1 ) : NEW_LINE INDENT CountB [ i ] = cntEven NEW_LINE DEDENT else : NEW_LINE INDENT CountB [ i ] = cntOdd NEW_LINE DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT print ( CountB [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = [ 4 , 2 , 15 , 9 , 8 , 8 ] NEW_LINE B = [ 3 , 4 , 22 ] NEW_LINE countEvenBit ( A , B , 6 , 3 ) NEW_LINE DEDENT