Palindromic string

question–>
https://practice.geeksforgeeks.org/problems/anagram-palindrome/0

code–>

Hey @sheikhhaji18

#include <iostream>
#include<string>
#include<map>
using namespace std;

int main() {
	//code
	int t;
// 	map<char,int> m;not here but inside loop
	cin>>t;
	while(t--){
	    map<char,int> m;//declared here
	    string s;
	    cin>>s;
	    for(int i=0;i<s.length();i++){
	        if(m.count(s[i])==0){
	            m[s[i]]=1;
	        }
	        else{
	            m[s[i]]++;
	        }
	    }
	    bool flag=true;
        bool once=true;//added
	    for(auto x:m){
	        if(x.second%2!=0){ //updated this
	            // cout<<"No"<<endl; removed
                if(once)once=false;//added
                else{ //added
                    flag=false;
                    break;
                }
	        }
	    }
	    if(flag)
	    cout<<"Yes"<<endl;
        else cout<<"No"<<endl;//added here
	}
	return 0;
}

There can be atmost one char with odd freq for it to be anagram palindromic

thx @Kartikkhariwal1

1 Like

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.