It's simply just finding the number of sub-arrays with sum 0


#1
int Solution::solve(vector<int> &A, int B, int C) 
{
    unordered_map<int,int>m;
    int sum=0,count=0;
    for(int i=0;i<A.size();i++)
    {
        if(A[i]==B)
        {
            sum+=1;
        }
        else if(A[i]==C)
        {
            sum-=1;
        }
        if(sum==0)
        {
            count++;
        }
        if(m.find(sum)!=m.end())
        {
            count+=m[sum];
        }
        m[sum]++;
    }
    return count;
}