Google Interview Question Palindrome
Anonymous User
4330

A string is a palindrome if it reads the same backward as forward. For

example, "madam" and "racecar" are palindromes, but "milk" is not.

We are given an array of N strings in which each string consists of two

lowercase English letters. We would like to join as many strings as possible

to make as long and as unique as possible strings together as possible in

order to obtain a palindrome.

Write a function: which given an array A of length N containing two-letter

#strings, return the length of the longest palindrome that can be created by
#joining as many strings together as possbile from A.

Examples:

1. Given A = ["ck","kc","ho","kc"], the function should return 4 since the

longest palindromes that can be created from A are "ckkc" and "kcck" and their

length are both equal to 4

2. Given A = ["ab","hu","ba","nn"], the function should return 6 since the

longest palindromes that can be created from A are "abnnba" and "bannab", and

their lengths are both equal to 6

3. Given A = ["so","oo","kk","od"], the function should return 2, since the

only palindromes that can be created from A are "oo" and "kk", and their

lengths are both equal to 2

4. Given A= ["do", "go", "ok"], the function should return 0 since no

palindrome can be created from A.

'''
def solution(A):

'''

Comments (4)