Beautiful Pairs

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/coANgIdBKAk

    int beautifulPairs(vector<int> A, vector<int> B) {
        map<int, int> mp;
        int result = 0;
        for(int i = 0; i < A.size(); i++) mp[A[i]]++;
        for(int i = 0; i < B.size(); i++){
            if(mp[B[i]]){
                mp[B[i]]--;
                result++;
            }
        }
        return (result == A.size()) ? result - 1 : result + 1;
    }