[
math
bit manipulation
array
]
Leetcode 1835. Find XOR Sum of All Pairs Bitwise AND
Problem statement
https://leetcode.com/problems/find-xor-sum-of-all-pairs-bitwise-and/
Solution
We can use distribution property of XOR with rescepct to AND and writ is as the following oneliner.
Complexity
Time and space complexity is O(n)
.
Code
class Solution:
def getXORSum(self, A, B):
return reduce(xor, A) & reduce(xor, B)