C++ | Hashmap | Greedy
There could be 2 types of string \n-> same characters (aa)\n-> different characters (ab,cd etc)\n\nIf we have encountered both ab and ba we increment min(ab,ba)
There could be 2 types of string \n-> same characters (aa)\n-> different characters (ab,cd etc)\n\nIf we have encountered both ab and ba we increment min(ab,ba)*4 freq from map\nIf we encounter even number of aa,bb etc:- we take all of them into account.\nIf we encounter any odd number of aa, bb etc:- we can do count+=2 because any one of that could be put in the middle.\n\n```\nclass Solution {\npublic:\n    int longestPalindrome(vector<string>& words) {\n        unordered_map<string,int>mp;\n        for(string word:words)mp[word]++;\n        int count=0;\n         bool flag=0;\n        for(auto &i:mp)\n        {\n            string a=i.first;\n            string b=a;\n            reverse(b.begin(),b.end());\n            if(a==b){\n                if(!flag&&i.second%2)flag=true;\n                count+=(i.second/2)*4;\n                continue;\n            } \n            auto it=mp.find(b);\n            if(it!=mp.end())\n            {\n                count+=min(i.second,it->second)*4;\n                it->second=0;\n                i.second=0;\n            } \n        }\n        if(flag)count+=2;\n        return count;\n    }\n};\n```
['C']