Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,015 views

All past online assesments of Google can be found using the tag "google_oa" in the search bar.

Here is the link :  https://www.desiqna.in/tag/google_oa

in Online Assessments by Expert (34,270 points) | 1,015 views

1 Answer

0 like 0 dislike

Google Online Assessment  (OA) - Longest Palindrome

A string is a palindrome if it reads the same backward as forwards. For example, "madam" and "racecar" are palindromes, but "milk" is not.

We are given an array of N strings in which each string consist of two lowercase English letters. We would like to join as many strings together as possible in order to obtain a palindrome.

Input

  • arr: an array of length N containing two-letter strings

Output

the length of longest palindrome that can be created by joining as many strings together as possible form arr

Examples

Example 1:

Input:


 
1arr = ['ck', 'kc', 'ho', 'kc']

Output4

Explanation:

The longest palindrome are "ckkc" and "kcck", and their lengths are both equal to 4.

by Expert (34,270 points)