Approach:
xor
---------
4 2 2 4 6
k
x _______
Take running xor
x^k = xor then xor ^ k = x we do this
#include<bits/stdc++.h>
int subarraysWithSumK(vector < int > arr, int b) {
int n = arr.size();
int count = 0, x = 0;
// xor, count;
unordered_map<int,int> mp;
for(int i=0; i<n; i++){
x ^= arr[i];
if(x == b)
count++;
if(mp.find(x^b) != mp.end()){
count += mp[x^b];
}
// if(mp.find(x^b) == mp.end()){
mp[x]++;
// }
}
return count;
}