Longest Palindrome After Substring Concatenation I

You are given two strings, s and t.

You can create a new string by selecting a substring from s (possibly empty) and a substring from t (possibly empty), then concatenating them in order.

Return the length of the longest palindrome that can be formed this way.

Example 1
Inputs = "a", t = "a"
Output2
Concatenating "a" from s and "a" from t results in "aa", which is a palindrome of length 2.
Example 2
Inputs = "abc", t = "def"
Output1
Since all characters are different, the longest palindrome is any single character, so the answer is 1.

Constraints

  • 1 <= s.length, t.length <= 30
  • s and t consist of lowercase English letters.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate