We’re preparing your current view and syncing the latest data.
Given two strings word1 and word2, your task is to find the length of the longest palindrome that can be formed by concatenating a non-empty substring from word1 and a non-empty substring from word2. The concatenation is done by appending the substring from word2 after the substring from word1. Return the length of the longest palindrome achievable in this way.
Two strings word1 and word2, each consisting of lowercase English letters.
An integer representing the length of the longest palindrome that can be constructed as described.
1 <= word1.length, word2.length <= 10^5; word1 and word2 consist only of lowercase English letters.
Example 1
Input
word1 = "cac", word2 = "bb"
Output
5
Explanation
One possible palindrome is "cabbac", formed by substring "ca" from word1 and substring "bb" from word2 resulting in a palindrome of length 5.