• + 0 comments

    For every un-set bit , there are 2 posiiblities of a number that when added to the original number would give the same answer , if xored

    So , count the number of unset bits , and then raise it to the power of 2 , to get all combinations of numbers that when added to n will give the same result as to when xored by n

    def sumXor(n): # Write your code here ct = 0 while n: if n&1==0: ct+=1 n>>=1 return 2**ct

    `