Count The Number of Mirror words and Words with mirrors
Approach\n1. make the frequency map wordCount \n2. for each word in wordCount, check if its a \'mirror\'\n\t- if it is, count the number of \'pairs\' and \'maid
## Approach\n1. make the frequency map `wordCount` \n2. for each `word` in `wordCount`, check if its a \'mirror\'\n\t- if it is, count the number of \'pairs\' and \'maiden mirrors\' that can be formed with it\n3. check if it has a mirror in `wordCount`\n\t - count the number of \'pairs\' that can be made with it \n4. each pair is 4 character long, and only one maiden mirror could be added, return the length thus formed\n\n**terminologies**\nmirror : a string that already a palindrome, e.g: \'aa\', \'xx\'\nhas mirror : if the reverse of the string exists in the input, eg. for \'ab\', \u2203 \'ba\' \nmaiden mirror : mirrors that can not form a pair, these must be placed in the middle of the palindrome\n\n## Code \n```java\nclass Solution {\n    public int longestPalindrome(String[] words) {\n        int res=0, maidenMirrors = 0;\n        HashMap<String, Integer> wordCount=new HashMap<>();\n        for(String word: words) wordCount.put(word, wordCount.getOrDefault(word, 0)+1);\n        for(String word: wordCount.keySet())\n        {\n            char a = word.charAt(0), b = word.charAt(1);\n            int count = wordCount.get(word);\n            if(a == b) {\n                //is mirror\n                maidenMirrors += count%2;\n                res += count/2;\n            }\n            else if(a < b && wordCount.containsKey(b+""+a)) {\n                //has mirror\n                res += Math.min(count, wordCount.get(b+""+a));\n            }\n        }\n        \n        res *= 4;\n        if(maidenMirrors > 0) res += 2;\n        return res;\n    }\n}\n```\n\n## Analysis \nTime : O(n)\nSpace : O(n)
['Java']