Talentd
FleetCode

1745. Palindrome Partitioning IV

Hard45.8% acceptance1 company

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 the same string when reversed.

Example 1:

Input: s = "abcbdd"
Output: true
Explanation: "abcbdd" = "a" + "bcb" + "dd", and all three substrings are palindromes.

Example 2:

Input: s = "bcbddxy"
Output: false
Explanation: s cannot be split into 3 palindromes.

Constraints:

  • 3 <= s.length <= 2000
  • s​​​​​​ consists only of lowercase English letters.

Asked at 1 company

Hints open one at a time

Hint 1
Preprocess checking palindromes in O(1)
Hint 2
Note that one string is a prefix and another one is a suffix you can try brute forcing the rest
10:09
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def checkPartitioning(self, s: str) -> bool:
3
Starter codePython 3Spaces: 4
Examples
Input
"abcbdd"
Input
"bcbddxy"
Your code is saved on this device.Solution