We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Bit Manipulation
- Sum vs XOR
- Discussions
Sum vs XOR
Sum vs XOR
Sort by
recency
|
245 Discussions
|
Please Login in order to post a comment
Here is my C++ solution, you can watch the explanation here : https://youtu.be/yj0yNv6BZa8
More at https://github.com/pakbungdesu/hackerrank-problem-solving.git
Java
Pyhon
Haskell
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
`