Find Reversed
We can build out our palindrome by attaching original and reversed strings left and right. If we have a spare symmetric string, we can put it in the middle.\n\n
We can build out our palindrome by attaching original and reversed strings left and right. If we have a spare symmetric string, we can put it in the middle.\n\nWe count all strings using a hashmap. Then, for each string, we search for the reverse string in the hashmap. This way, we can figure out how many times we can attach the original and reversed strings to our palindrome.\n\nNote that, for the symmetric string, we only have one count, so we can attach it `cnt / 2 ` times. \n\n**C++**\n```cpp\nint longestPalindrome(vector<string>& words) {\n    unordered_map<string, int> m;\n    for (auto &w : words)\n        ++m[w];\n    int res = 0, center = 0, sz = 2;\n    for (auto &[w, cnt] : m) {\n        auto reversed = string(rbegin(w), rend(w));\n        if (w == reversed) {\n            res += 2 * (cnt / 2);\n            center |= cnt % 2;\n        }\n        else {\n            auto it = m.find(reversed);\n            if (it != end(m))\n                res += min(cnt, it->second);\n        }\n    }\n    return sz * res + (center ? sz : 0);\n}\n```
['C']