C++ | Without Hashmap | Using 2D Counter Array ✅
Intuition:\nWe are given a words array which contains only strings each of Two Letters.\nSo, we basically have two conditions to check:\n When both letters are 
**Intuition:**\nWe are given a words `array` which contains only `strings` each of `Two` Letters.\nSo, we basically have `two` `conditions` to check:\n* When both letters are `different`\n* When both letters are `same`\n\nSo at any point when we found a `mirror` of the word increase `ans` by `+4`\nAlso if at any point we found a word with `same` letters then just increase `ans` by `+2`\n\n![Image](https://leetcode.com/problems/longest-palindrome-by-concatenating-two-letter-words/Documents/2131/2131_examples.drawio.svg)\n\n\n**Code:**\n```\nclass Solution {\npublic:\n    int longestPalindrome(vector<string>& words) {\n        int n = words.size();\n        vector<vector<int>> counter(26,vector<int>(26,0));\n        int ans=0;\n        // for different letters in the word\n        for(string s:words){\n            int a = s[0]-\'a\'; // first letter\n            int b = s[1]-\'a\'; // second letter\n            // if the reverse of the word exists i.e like for "lc" if "cl" exists\n            if(counter[b][a]) {\n                ans+=4; // count increase by 2+2 = 4\n                counter[b][a]--; // remove the occurance of the word from counter\n            }\n            else counter[a][b]++; // if original doesn\'t exits in counter array then increase in counter\n        }\n        // for same letters in the word\n        for(int i=0;i<26;i++){\n            if(counter[i][i]){ // if both the letters are same\n                ans+=2; // increase by 2 i.e like for "gg" \n                break;\n            }\n        }\n        return ans;\n    }\n};\n```\n----\n**Time Complexity :** `O(N)`\n**Space Complexity :** `O(26*26)`\n\n
['String', 'C', 'C++']