2
public int longestPalindrome(String[] words) {3
int[][] freq = new int[26][26]; // array for all alphabet combinations4
for (String word : words)5
freq[word.charAt(0) - 'a'][6
word.charAt(1) - 'a']++; // here we first increase the freq for every word7
int left = 0; // to store freq counts9
for (int i = 0; i != 26; i++) { // iterate over our array10
odd |= (freq[i][i] & 1) == 1; // means odd number of freq for similar words are there11
left += freq[i][i] / 2;12
for (int j = i + 1; j != 26; j++) // nested iteration to find non similar pairs13
left += Math.min(freq[i][j], freq[j][i]); // taking min times from both present15
int res = left * 2 * 2; // res from total freq found!!17
res += 2; // if odd then adding 2