Python Solution using Hash Table
Intuition\n Describe your first thoughts on how to solve this problem. \n- There are two patterns to consider\n  - ("xy", "yx") or\n  - ("xx", "xx")\n- We can c
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- There are two patterns to consider\n  - ```("xy", "yx")``` or\n  - ```("xx", "xx")```\n- We can count the number of pairs ```("xy", "yx")```\n- We can think of ```("xx", "xx")``` as the same type of pair \n  - except for the case where we can put another ```"xx"``` in the middle (does not need to be a pair)\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Initialize ```res``` as ```0``` to keep track of the current length of the longest palindrome.\n- Create a dictionary ```d``` to keep track of the count of each word we\'ve seen so far.\n- Iterate through ```words```, look at each ```w```:\n  - check if there is any available ```rw``` (the reverse of the current ```w```) in ```d``` by looking at the count of ```rw```\n    - if the count of ```rw``` is larger than zero, we \n      - take ```rw``` and ```w``` (this means that we perform ```d[rw] -= 1``` and do not thing for ```d[w]```) and\n      - add 4 to ```res```.\n    - else (which means that there\'s currently no available ```rw``` in ```d```)\n      - we add 1 avaible ```w``` to ```d```: ```d[w] += 1```\n- Lastly, check if there\'s an extra word of the pattern ```"xx"```, which we can put in the middle.\n# Complexity\n- Time complexity: $O(n)$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $O(n)$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def longestPalindrome(self, words: List[str]) -> int:\n        d = collections.defaultdict(int)\n        res = 0\n        for w in words:\n            rw = w[::-1]\n            if d[rw] > 0:\n                res += 4\n                d[rw] -= 1\n            else:    \n                d[w] += 1\n        for w in d.keys():\n            if w[0] == w[1] and d[w] > 0:\n                res += 2\n                break\n                \n        return res\n        \n```
['Hash Table', 'Python3']