C++ easy understandable solution with proper comment


#1

int Solution::solve(vector &A, int B) {
int n=A.size();
int prexor[n]; // prefix xor array
prexor[0]=A[0];
for(int i=1;i<n;i++){
prexor[i]=prexor[i-1]^A[i];
}
int ans=0;
unordered_map<int,int>m;
for(int i=0;i<n;i++){
int x=B^prexor[i];
if(prexor[i]==B) ans++; // if prifix xor of this array is equal to given xor than increse the counter
if(m.find(x)!=m.end()){
ans+=m[x]; // add the freq. of remainning xor
}

    m[prexor[i]]++;
}
return ans;

}