Class Solution
java.lang.Object
g1101_1200.s1147_longest_chunked_palindrome_decomposition.Solution
1147 - Longest Chunked Palindrome Decomposition.<p>Hard</p>
<p>You are given a string <code>text</code>. You should split it to k substrings <code>(subtext<sub>1</sub>, subtext<sub>2</sub>, …, subtext<sub>k</sub>)</code> such that:</p>
<ul>
<li><code>subtext<sub>i</sub></code> is a <strong>non-empty</strong> string.</li>
<li>The concatenation of all the substrings is equal to <code>text</code> (i.e., <code>subtext<sub>1</sub> + subtext<sub>2</sub> + … + subtext<sub>k</sub> == text</code>).</li>
<li><code>subtext<sub>i</sub> == subtext<sub>k - i + 1</sub></code> for all valid values of <code>i</code> (i.e., <code>1 <= i <= k</code>).</li>
</ul>
<p>Return the largest possible value of <code>k</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> text = “ghiabcdefhelloadamhelloabcdefghi”</p>
<p><strong>Output:</strong> 7</p>
<p><strong>Explanation:</strong> We can split the string on “(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)”.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> text = “merchant”</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> We can split the string on “(merchant)”.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> text = “antaprezatepzapreanta”</p>
<p><strong>Output:</strong> 11</p>
<p><strong>Explanation:</strong> We can split the string on “(a)(nt)(a)(pre)(za)(tpe)(za)(pre)(a)(nt)(a)”.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= text.length <= 1000</code></li>
<li><code>text</code> consists only of lowercase English characters.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
longestDecomposition
-