#1616
Split Two Strings to Make Palindrome
expert · 1125 · lc medium +32 · verified · 32.1% accepted · 780 likes · top 10%
Description
You are given two equal-length strings a and b. Split both at the same index to get aprefix + asuffix and bprefix + bsuffix. Either prefix or suffix may be empty. Return true if aprefix + bsuffix or bprefix + asuffix forms a palindrome for some split index.
Example 1:
Input: a = "x", b = "y"
Output: true
Explaination: If either a or b are palindromes the answer is true since you can split in the following way:
aprefix = "", asuffix = "x"
bprefix = "", bsuffix = "y"
Then, aprefix + bsuffix = "" + "y" = "y", which is a palindrome.
Example 2:
Input: a = "xbdef", b = "xecab"
Output: false
Example 3:
Input: a = "ulacfd", b = "jizalu"
Output: true
Explaination: Split them at index 3:
aprefix = "ula", asuffix = "cfd"
bprefix = "jiz", bsuffix = "alu"
Then, aprefix + bsuffix = "ula" + "alu" = "ulaalu", which is a palindrome.
Code
1
2
3