Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    1147 - Longest Chunked Palindrome Decomposition.

    Hard

    You are given a string text. You should split it to k substrings <code>(subtext<sub>1</sub>, subtext<sub>2</sub>, ..., subtext<sub>k</sub>)</code> such that:

    • <code>subtext<sub>i</sub></code> is a non-empty string.

    • The concatenation of all the substrings is equal to text (i.e., <code>subtext<sub>1</sub> + subtext<sub>2</sub> + ... + subtext<sub>k</sub> == text</code>).

    • <code>subtext<sub>i</sub> == subtext<sub>k - i + 1</sub></code> for all valid values of i (i.e., 1 &lt;= i &lt;= k).

    Return the largest possible value of k.

    Example 1:

    Input: text = "ghiabcdefhelloadamhelloabcdefghi"

    Output: 7

    Explanation: We can split the string on "(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)".

    Example 2:

    Input: text = "merchant"

    Output: 1

    Explanation: We can split the string on "(merchant)".

    Example 3:

    Input: text = "antaprezatepzapreanta"

    Output: 11

    Explanation: We can split the string on "(a)(nt)(a)(pre)(za)(tpe)(za)(pre)(a)(nt)(a)".

    Constraints:

    • 1 &lt;= text.length &lt;= 1000

    • text consists only of lowercase English characters.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer longestDecomposition(String text)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait