In the Split Two Strings to Make Palindrome interview question, you are given two strings and of the same length. You need to check if there exists an index such that either or forms a palindrome. The split must happen at the same index for both strings.
This is a classic Google interview question that tests your proficiency with the Two Pointers interview pattern and your ability to identify symmetry. It requires a clean, modular approach to avoid redundant code and handle the logic for both and efficiently.
The algorithm uses the Two Pointers technique. You compare the characters of from the start and from the end. As long as they match, you move the pointers inward. When you find a mismatch at indices and , the only way to form a palindrome is if the remaining middle portion of either string or string (from to ) is itself a palindrome.
Let and .
Always look for ways to reuse code. In this Split Two Strings to Make Palindrome coding problem, the logic for both combinations is nearly identical. Write a generic function that takes two strings and checks the condition, then call it twice with the arguments swapped.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Swap Adjacent in LR String | Medium | Solve | |
| Magical String | Medium | Solve | |
| Move Pieces to Obtain a String | Medium | Solve | |
| One Edit Distance | Medium | Solve | |
| Compare Version Numbers | Medium | Solve |