Simple c++ solution with easy understanding


#1

int Solution::solve(vector &A) {

// Waris chugh

int var = A[0];
unordered_map<int,vector<int>> mp;
mp[var].push_back(0);
mp[0].push_back(-1);
int cou = 0;
for(int i = 1;i<A.size();i++)
{
    var = var ^ A[i];
    if(mp.count(var) > 0)
    {
        for(int j = 0;j<mp[var].size();j++)
        {
            cou += (i - mp[var][j] - 1);
        }
        mp[var].push_back(i);
    }
    else
    {
        mp[var].push_back(i);
    }
}
return cou;

}