Java | HashMap
\nclass Solution {\n    public int longestPalindrome(String[] words) {\n        HashMap<String,Integer> map = new HashMap<>();\n        int max = 0;\n        in
```\nclass Solution {\n    public int longestPalindrome(String[] words) {\n        HashMap<String,Integer> map = new HashMap<>();\n        int max = 0;\n        int palin = 0; // Number of unpaired palindrome strings\n        for(String word : words)\n        {\n            String rev = ""+word.charAt(1)+word.charAt(0); // Reverse of string\n            if(map.getOrDefault(rev,0)> 0)\n            {\n                max += 4;\n                map.put(rev,map.get(rev)-1);\n                if(word.equals(rev)) // Palindromic string paired, so decrease count\n                    palin--;\n            }\n            else\n            {\n                if(word.equals(rev))\n                    palin++;\n                map.put(word,map.getOrDefault(word,0)+1);\n            }\n        }\n        if(palin >= 1) // A single unpaired palindromic string can be placed in the middle\n            max += 2; // Example: abccba\n        return max;\n    }\n}\n```
['Java']