Easy to understand soln (C++)


#1
int Solution::solve(vector<int> &A, int B) {
    unordered_map<int, int> map;
    int count = 0;
    int xorr = 0;
    for(auto it: A){
        //do prefix xor w each ele
        xorr ^= it;
        
        if(xorr == B) count++;
        if(map.find(xorr ^ B) != map.end()) count += map[xorr ^ B];
        map[xorr] += 1;
    }
    return count;
    // Refer Striver (TuF) vid on YT
}