Detailed Explanation || Ordered Map || O(n)
Approach\nExplained throughout code with the help of comments\n\n# Complexity\n- Time complexity:\n    O(n)\n- Space complexity:\n    O(n)\n\n# Code\n\nclass So
# Approach\nExplained throughout code with the help of comments\n\n# Complexity\n- Time complexity:\n    O(n)\n- Space complexity:\n    O(n)\n\n# Code\n```\nclass Solution {\npublic:\n    int longestPalindrome(vector<string>& words) {\n        int n = words.size(), ans =0;\n        map <string, int> m;                    //make a hash map for all the strings\n        for (auto i: words){\n            m[i]++;\n        }\n        bool mid = false;\n        for (auto it: m){\n            string curr = it.first;             \n            if (curr[0]==curr[1]){              //traversing the map to check same letter repeted strings of type "xx"\n                if (it.second%2!=0){\n                    if (!mid){\n                        ans += it.second*2;\n                        mid = true;\n                    }\n                    else{\n                        ans += (it.second-1)*2;\n                    }\n                }\n                else{\n                    ans += it.second*2;\n                }\n            }\n            else{\n                swap(curr[0], curr[1]);\n                if (m.find(curr)!=m.end()){\n                    ans += 4*(min (it.second, m[curr]));\n                    m[curr]=0;\n                    m[it.first]=0;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['Ordered Map', 'C++']