Repository containing solution for #SdeSheetChallenge by striver
Given an array of integers arr[] and a number m, count the number of subarrays having XOR of their elements as m.
int countSubarrayWithXOR(vector<int>& a, int b)
{
map<int, int> freq;
int cnt = 0, xorr = 0;
for (auto x : a) {
xorr = xorr ^ x;
if (xorr == b)
cnt++;
if (freq.count(xorr ^ b))
cnt += freq[xorr ^ b];
freq[xorr] += 1;
}
return cnt;
}