Suppose we have two numbers x and y we have to check whether the binary representation of x and y are anagram of each other or not.
So, if the input is like x = 9 y = 12, then the output will be True as binary representation of 9 is 1001 and binary representation of 12 is 1100, so these two are anagram of each other.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def set_bit_count(num) : cnt = 0 while num: cnt += num & 1 num >>= 1 return cnt def solve(x, y) : if set_bit_count(x) == set_bit_count(y): return True return False x = 9 y = 12 print(solve(x, y))