1963. Find XOR Sum of All Pairs Bitwise AND
My accepted Python solution to LeetCode problem 1963, Find XOR Sum of All Pairs Bitwise AND, running in 15ms.
- Difficulty: Hard
- Python
- Runtime 15ms
- Memory 31.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 15ms, memory 31.2MB, accepted 2026-01-02.
class Solution:
def getXORSum(self, arr1: List[int], arr2: List[int]) -> int:
# Key insight: XOR of (a AND b) for all pairs equals (XOR of arr1) AND (XOR of arr2)
# This is because XOR distributes over AND in a specific way
from functools import reduce
from operator import xor
xor1 = reduce(xor, arr1, 0)
xor2 = reduce(xor, arr2, 0)
return xor1 & xor2