1147. Longest Chunked Palindrome Decomposition Hard

@problem@discussion
#Two Pointers#String#Dynamic Programming#Greedy#Rolling Hash#Hash Function



1/**
2 * [1147] Longest Chunked Palindrome Decomposition
3 *
4 * You are given a string text. You should split it to k substrings (subtext1, subtext2, ..., subtextk) such that:
5 * 
6 * 	subtexti is a non-empty string.
7 * 	The concatenation of all the substrings is equal to text (i.e., subtext1 + subtext2 + ... + subtextk == text).
8 * 	subtexti == subtextk - i + 1 for all valid values of i (i.e., 1 <= i <= k).
9 * 
10 * Return the largest possible value of k.
11 *  
12 * Example 1:
13 * 
14 * Input: text = "ghiabcdefhelloadamhelloabcdefghi"
15 * Output: 7
16 * Explanation: We can split the string on "(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)".
17 * 
18 * Example 2:
19 * 
20 * Input: text = "merchant"
21 * Output: 1
22 * Explanation: We can split the string on "(merchant)".
23 * 
24 * Example 3:
25 * 
26 * Input: text = "antaprezatepzapreanta"
27 * Output: 11
28 * Explanation: We can split the string on "(a)(nt)(a)(pre)(za)(tep)(za)(pre)(a)(nt)(a)".
29 * 
30 *  
31 * Constraints:
32 * 
33 * 	1 <= text.length <= 1000
34 * 	text consists only of lowercase English characters.
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/longest-chunked-palindrome-decomposition/
40// discuss: https://leetcode.com/problems/longest-chunked-palindrome-decomposition/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn longest_decomposition(text: String) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_1147() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.