You are given a string text. You should split it to k substrings (subtext1, subtext2, ..., subtextk) such that:


	subtexti is a non-empty string.
	The concatenation of all the substrings is equal to text (i.e., subtext1 + subtext2 + ... + subtextk == text).
	subtexti == subtextk - i + 1 for all valid values of i (i.e., 1 &lt;= i &lt;= k).


Return the largest possible value of k.

&nbsp;
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)(tep)(za)(pre)(a)(nt)(a)".


&nbsp;
Constraints:


	1 &lt;= text.length &lt;= 1000
	text consists only of lowercase English characters.


class Solution:
    def longestDecomposition(self, text: str) -> int:
        left, right = 0, len(text) - 1
        sol, last_left = 0, 0
        a, b = deque(), deque()
        while right > left:
            a.append(text[left])
            b.appendleft(text[right])
            if a == b:
                sol += 2
                last_left = left
                a, b = deque(), deque()
            right -= 1
            left += 1
        if left == right or left > last_left + 1:
            sol += 1
        return max(sol, 1)
class Solution {

 public int longestDecomposition(String text) {
    int n = text.length();   
    for (int i = 0; i < n/2; i++) 
        if (text.substring(0, i + 1).equals(text.substring(n-1-i, n))) 
            return 2+longestDecomposition(text.substring(i+1, n-1-i));
    return (n==0)?0:1;
}
}
class Solution {
public:
    int longestDecomposition(string text) {
        if(text.size() == 0)
            return 0;
        int i = 0;
        deque<char> sFront;
        deque<char> sBack;
        while(i < text.size() / 2){
            sFront.push_back(text[i]);
            sBack.push_front(text[text.size() - 1 - i]);
            if(sFront == sBack)
                return 2 + longestDecomposition(text.substr(i + 1, text.size() - 2*(i+1)));
            i++;
        }
        return 1;
    }
};
var longestDecomposition = function(text) {
    var i = 1
    var output = 0
    while(i < text.length)
    {
        if(text.substring(0,i) == text.substring(text.length-i))
        {
            output += 2 //add 2 to simulate adding to both sides of output array
            text = text.substring(i,text.length-i) //cut text to simulate popping off of both sides
            i=1
        } else {
            i++
        }
    }
    
    return text ? output + 1 : output //if there's any text leftover that didn't have a match, it's the middle and would add 1 to output array
}
Longest Chunked Palindrome Decomposition