C++ | Using only Map


#1
vector<int> Solution::solve(vector<int> &A, vector<int> &B, vector<int> &C) {
    map<int,int> mp;
    vector<int> result;
    for(int i=0;i<A.size();i++) mp[A[i]]=1;
    for(int i=0;i<B.size();i++){
        if(mp.count(B[i])){
            if(mp[B[i]]==1) mp[B[i]]=4;
        }
        else mp[B[i]]=2;
    }
    for(int i=0;i<C.size();i++){
        if(mp.count(C[i])){
            if(mp[C[i]]==2 || mp[C[i]]==1) mp[C[i]]=4;
        }
        else mp[C[i]]=3;
    }
    for(auto i=mp.begin();i!=mp.end();i++){
        if(i->second==4) result.push_back(i->first);
    }
    return result;
}

#2

why is count(B[i]) needed;

coz the B[i] is key and if it’s already present in the map then count won’t be needed it, but I tried code without it and was getting an error for this test case.
A : [ 56, 56, 34, 34, 72, 71 ]
B : [ 56, 56, 34, 34, 72, 71 ]
C : [ 56, 56, 34, 34, 72, 71 ]

Can u please explain?