Maximize Total Number of Bits of Pairwise XORs


  • 0
    A

    Input: m, n (where m < n)
    Output: Give m distinct integers from 1 to n that maximizes the total number of 1-bits in pairwise XORs (explained below).

    Total number of bits in all pairwise XORs given an array of integers x:
    F(x) = sum( number_of_bits( xor(x[i], x[j]) ) for i = 1 to m, j = (i + 1) to m )

    Example:
    if x = [4, 6, 8], let NoB(num) return number of 1 bits in the number.
    F(x) = NoB(4 xor 6) + NoB(4 xor 8) + NoB(6 xor 8)
    = NoB(2) + NoB(12) + NoB(14)
    = 1 + 2 + 3
    = 6


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.