Python3 Hash map approach
\nMain idea:\n\nTo look at all possible types of variations of palindrome construction let\'s use the example: \n\n\twords = ["ab", "ee", "cc", "ba", "ee", "cc"
\n**Main idea:**\n\nTo look at all possible types of variations of palindrome construction let\'s use the example: \n\n\twords = ["ab", "ee", "cc", "ba", "ee", "cc", "cc"]\n\nTo construct a palindrome we can use three types of "words":\n1. The same "word" as we met before, but at reversed order: \n\n\t\t"ab" + ... + "ba"\n2.  An even number of "words" which consist of the same letter:  \n\n\t\t"ee" + ... + "ee" \n3.  Odd number of "words" which consist of the same letter: \n\n\t\t"cc"  + ... + "cc" + ... + "cc" \n\n\t(i.e we put one "word" in the middle of the palindrome, **but** we can do  that only for **one** "word" of that type).\n\nSo, for that list of **words**, based on the above, we can construct a palindrome:\n\n\t\t"ab" + "ee" + "cc" + "cc" + "cc" + "ee" + "ba"\nor\n\n\t\t "cc" + "ab" + "ee" + "cc"  + "ee" + "ba" + "cc"\nor any other, based on the same logic.\n\n**Algorithm:**\n\nWhile we going through the list of **words**  let\'s reverse them and put them as a key of the dict, where value is the number of such words. If we will meet a "word" from the dict then we already met his unreversed "brother" therefore we can use both of them as the part of palindrome. All those pairs give  **+4** to the length of the palindrome.  \n\nAs a result when we go through the whole list of words we will calculate all types of "word"  which were mentioned at the points 1 and 2. \n\nTo take into account a "word" which we could place in the middle, we will go through the dict and check if there is any "word" consisting of the same letter left.\n\n**Complexity:**\nTime complexity: O(n)\nSpace complexity: O(n)\n\n\n```\n\nclass Solution:\n\tdef longestPalindrome(self, words: List[str]) -> int:\n\t\tans, rev = 0, defaultdict(int)\n\t\tfor word in words:\n\t\t\tif rev[word] > 0:\n\t\t\t\tans += 4\n\t\t\t\trev[word] -= 1\n\t\t\telse:\n\t\t\t\trev[word[::-1]] += 1\n  \n\t  return ans + (2 if any(k[0] == k[1] and v > 0 for k, v in rev.items()) else 0)\n```\n
['Hash Table', 'Python3']