Unordered Map | Hash Map | C++ | O(N) | Simple Approach
Intuition\nThe intuition to the solution lies in counting the number of pairs that are reverse of each other, as they can together form a pallindrome. After all
# Intuition\nThe intuition to the solution lies in counting the number of pairs that are reverse of each other, as they can together form a pallindrome. After all the pairs are found, if we get a string whose both characters are same, we can put that string in the middle increasing the size of the pallindrome by 2.  \n\n# Approach\n- Create an ordered/Unordered map to maintain the frequency while iterating through the vector \'words\'.\n- Iterate through \'words\'.\n- If there exists a string that is reverse of the current string.\n- - Increase ans by 4, and decrease the frequency of the string that is reverse of the current string.\n- else\n- - Increase the frequency of the crrent string.\n- Now check for any string in the map whose both characters are same.\n- - if such string exists, increase ans by 2 and return ans.\n- return ans.\n\n# Complexity\n- Time complexity: O(N), Where N is the size of vector words.\n\n- Space complexity: O(N), Where N is the size of vector words.\n\n# Code\n```\nclass Solution {\npublic:\n    int longestPalindrome(vector<string>& words) {\n        int ans = 0 ;\n        unordered_map<string, int> fre ;\n        for(string &str : words)\n        {\n            reverse(str.begin(), str.end()) ;\n            if(fre.find(str) != fre.end())\n            {\n                ans += 4 ;\n                fre[str]-- ;\n                if(fre[str] == 0) fre.erase(str) ;\n            }\n            else\n            {\n                reverse(str.begin(), str.end()) ;\n                fre[str]++ ;\n            }\n        }\n        for(pair<string,int> x : fre)\n        {\n            if(x.first[0] == x.first[1])\n            {\n                ans += 2 ;\n                return ans ;\n            }\n        }\n        return ans ;\n    }\n};\n```
['Hash Table', 'Ordered Map', 'C++']