Look at this very short solution using XOR . Y am I getting partial marks? Using Python


#1


class Solution:
# @param A : list of integers
# @return an integer

def f(self,x,y):
    count=0
    for i in bin(x^y).replace('0b',''):
        count+=int(i)
    return count

def cntBits(self, A):
    ans=0
    for i in range(len(A)-1):
        for j in range(i+1, len(A)):
            ans+=self.f(A[i], A[j])
    return 2*ans


#2

I did the same in C++ but look at the complexity it’s O(n^2)
Optimize it and it is accepting.