Palindromes Everywhere

4.2

12 votes
Algorithms, Dynamic Programming, Medium, Palindromes, String Manipulation, Two dimensional
Problem

You are given 2 strings A and B.

Let F(S) denote a substring of S, possibly empty.

Let W=f(A)+f(B),  (+=concatenation)

Find the maximum possible length of such a string W which is also a Palindrome.

Note

  • The strings consist of lower case Latin letters.

Input Format

  • First Line contains the string A.
  • Second Line contains the string B.

Output Format

  • Print the maximum possible length of a palindromic string W

Constraints

  • 1|A|,|B|103
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The maximum length palindromic string W we can get is bdb. Hence answer is 3.

Editor Image

?