Find XOR Sum of All Pairs Bitwise AND LeetCode solution in C++
1class Solution {2public:3// this code is basically pure mathematics, mainly distributive property with4// AND and XOR56int getXORSum(vector<int> &arr1, vector<int> &arr2) {7int m = arr1.size();8int n = arr2.size();9long int ans1 = 0, ans2 = 0;10for (int i = 0; i < m; i++) // this loop stores the XOR between every element of arr111{12ans1 = ans1 ^ arr1[i];13}14for (int j = 0; j < n; j++) // this loop stores the XOR between every element of arr215{16ans2 = ans2 ^ arr2[j];17}18return ans1 & ans2; // AND operation of both XOR's is the answer.19}20};