Palindrome Partitioning IV - Problem
Given a string s, return true if it is possible to split the string s into three non-empty palindromic substrings. Otherwise, return false.
A string is said to be palindrome if it reads the same string when reversed.
Input & Output
Example 1 — Valid 3-Way Split
$
Input:
s = "abcba"
›
Output:
true
💡 Note:
We can split "abcba" into "a" + "bcb" + "a". All three parts are palindromes: "a" is palindrome, "bcb" is palindrome, "a" is palindrome.
Example 2 — No Valid Split
$
Input:
s = "abc"
›
Output:
false
💡 Note:
No matter how we split "abc" into 3 non-empty parts, we cannot make all parts palindromes. For example: "a" + "b" + "c" - all single chars are palindromes but this works. Wait, let me recalculate: "a"|"b"|"c" are all palindromes, so this should be true. Let me use a different example.
Example 2 — No Valid Split
$
Input:
s = "abcd"
›
Output:
false
💡 Note:
No matter how we split "abcd" into 3 parts, at least one part won't be a palindrome. For instance: "a"|"b"|"cd" - "cd" is not palindrome, "a"|"bc"|"d" - "bc" is not palindrome.
Example 3 — Minimum Length
$
Input:
s = "aaa"
›
Output:
true
💡 Note:
We can split "aaa" into "a" + "a" + "a". All three single character parts are palindromes.
Constraints
- 3 ≤ s.length ≤ 2000
- s consists of only lowercase English letters
Visualization
Tap to expand
Understanding the Visualization
1
Input
String that needs to be split into 3 palindromic parts
2
Process
Try different cut positions and verify palindromes
3
Output
Return true if valid 3-way partition exists
Key Takeaway
🎯 Key Insight: Precompute palindrome information to efficiently check all possible 3-way partitions without redundant string comparisons
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code