java.lang.Object
g1101_1200.s1147_longest_chunked_palindrome_decomposition.Solution

public class Solution extends Object
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>, &hellip;, 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> + &hellip; + 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 = &ldquo;ghiabcdefhelloadamhelloabcdefghi&rdquo;</p> <p><strong>Output:</strong> 7</p> <p><strong>Explanation:</strong> We can split the string on &ldquo;(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> text = &ldquo;merchant&rdquo;</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> We can split the string on &ldquo;(merchant)&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> text = &ldquo;antaprezatepzapreanta&rdquo;</p> <p><strong>Output:</strong> 11</p> <p><strong>Explanation:</strong> We can split the string on &ldquo;(a)(nt)(a)(pre)(za)(tpe)(za)(pre)(a)(nt)(a)&rdquo;.</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 Details

    • Solution

      public Solution()
  • Method Details

    • longestDecomposition

      public int longestDecomposition(String text)