Please tell my mistake in code

submission link
here i’ve used frequency map to count the frequency of every pair

I am not getting what u have actually done. But I would suggest to avoid erasing an element from set/map while traversing it. You can refer this thread from stackOverflow

You can refer this solution for above problem

	int T=1;
	cin>>T;
	while(T--){
		 int n;
		 cin>>n;
		 map<string,pair<int,int>>mp;
		 while(n--){
		     string s;
		     int nn;
		     cin>>s>>nn;
		     (nn==0)?mp[s].first++:mp[s].second++;
		 }
		 int ans=0;
		 for(pair<string,pair<int,int>>i:mp){
		     ans+=max(i.second.first,i.second.second);
		 }
		 cout<<ans<<"\n";
	} 
1 Like

Thank you very much for your reply .
Here i’ve created a pair to store string and boolean and the frequency of each pair is stored in map and also i stored the pair into set so that i get all the unique pairs .
After that i traverse the set and check if it is spam or not if it is spam then finding the maximum frequency and erasing both the spam pair or not spam pair if not then simply finding total .
for finding the spam pair i just use not operator with the second part of the current pair.