Description
Given an array of strings words where each string is 2 letters, return the longest palindrome that can be formed by concatenating words.
Examples
Input:
words = ["lc","cl","gg"]Output:
6Explanation:
lc + gg + cl = 6.
Input:
words = ["ab","ty","gy","fg","lc"]Output:
0Explanation:
Edge case returning zero.
Input:
words = ["aa","bb","cc","dd"]Output:
8Explanation:
All words are palindromes themselves. It is possible to use all of them: aa + bb + cc + dd = 8. When building a palindrome from pairs, identical letter words can all be placed in the middle.
Constraints
- •
1 ≤ words.length ≤ 10⁵