C++ | O(N)
cpp\nclass Solution {\npublic:\n    int longestPalindrome(vector<string>& words) {\n        map<string, int> stringMap;\n        for (const auto &x: words) {\n 
```cpp\nclass Solution {\npublic:\n    int longestPalindrome(vector<string>& words) {\n        map<string, int> stringMap;\n        for (const auto &x: words) {\n            ++stringMap[x];\n        }\n        int result = 0;\n        //Idea is that we start building the palindromic string from the middle\n        //we place all the strings which have the same characters in the middle if and\n        //only if their count is odd\n        //and then we pick each string and try to find it\'s reverse, and if found\n        //we use both the strings for palindrome, order doesn\'t matter here\n        bool haveUsedCommonString = false;\n        for (char ch = \'a\'; ch <= \'z\'; ++ch) {\n            string str;\n            str += ch;\n            str += ch;\n            if (stringMap.count(str) <= 0) continue;\n            int strCount = stringMap[str];\n            result += (2 * (strCount - (strCount&1)));\n            if ((strCount&1) && !haveUsedCommonString) {\n                result += 2;\n                haveUsedCommonString = true;\n            }\n            stringMap[str] = 0;\n        }\n        for (auto pp: stringMap) {\n            string rev = pp.first;\n            reverse(begin(rev), end(rev));\n            int canBeTaken = min(stringMap[rev], stringMap[pp.first]);\n            result += (4 * canBeTaken);\n            stringMap[rev] -= canBeTaken;\n            stringMap[pp.first] -= canBeTaken;\n        }\n        return result;\n    }\n};\n```
[]