Problem · String
Split a String into Three Palindromes
Learn this problemProblem statement
Given a string s, return true if it can be split into exactly three non-empty contiguous substrings such that every substring is a palindrome. Otherwise, return false.
A palindrome reads the same from left to right and right to left. The three substrings must preserve the original order and together use every character of s exactly once.
Function
canSplitIntoThreePalindromes(s: String) → booleanExamples
Example 1
s = "abcbdd"return = trueOne valid split is "a" | "bcb" | "dd". All three pieces are non-empty palindromes.
Example 2
s = "bcbddxy"return = falseNo placement of two split points makes all three resulting substrings palindromes.
Example 3
s = "aaa"return = trueThe only valid three-part split is "a" | "a" | "a", and each one-character substring is a palindrome.
Constraints
3 <= s.length <= 2000.scontains only lowercase English letters.