Sales by Match

  • + 0 comments

    c++

    int sockMerchant(int n, vector<int> ar) {
        unordered_map<int, int> frequencyMap;
        
        int nPairs = 0;
        
        for(int i = 0; i < ar.size(); ++i){
            frequencyMap[ar[i]] += 1;
            if(frequencyMap[ar[i]] % 2 == 0){
                nPairs +=1;
            }
        }
        
        return nPairs;
    }