********hash map ques

there was a queston in which we have to return count of duplicates
we are given a vector of names, weight and price
for example
name {bat,bag,golf,golf,golf}
weight {2,3,1,1,1}
price {5,6,2,8,2}

hashmap would look like
bat 2 5
bag 3 6
golf 1 2
golf 1 8
golf 1 2

output = 2
what is wrong in this function https://ideone.com/3x8aln

@ayu2321 use map and make key as pair<string,pair<int,int>> as using key duplicates can be found easily

will this work?
int duplicates(vectorname, vectorweight, vectorprice){
unordered_map<pair<string,pair<int,int>>,int>m;
unordered_map<string,int>freq;
for(int i=0;i<name.size();i++){

    if(m.find(name[i].first)!=m.end() && name[i].second)!=m.end()){
        m[make_pair(name[i],make_pair(weight[i],price[i]))]++;
    }
}
for(auto p: m){
    if(p.second>1){
        count++;
    }
}
return count;

}

@ayu2321 in unordered map you can’t make key as pair but in map you can

rest is the code fine?

@ayu2321
make map of that type
then when you input lets say
golf 1 2
do mp[golf 1 2]++
then iterate on it and keep storing maximum as max( maximum,it.second)

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.