Longest Chunked Palindrome Decomposition
HardStringsgreedy
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Split a string text into k non-empty consecutive pieces p1, p2, ..., pk whose concatenation is text, such that the pieces mirror each other: p1 == pk, p2 == p(k-1), and so on (a middle piece, if k is odd, only has to equal itself).
Return the **largest** possible k. Every string admits at least k = 1.
Examples
Input: text = "ghiabcdefhelloadamhelloabcdefghi"
Output: 7
(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi).
Input: text = "merchant"
Output: 1
No proper prefix equals a suffix, so the whole string is one piece.
Input: text = "antaprezatepzapreanta"
Output: 11
(a)(nt)(a)(pre)(za)(tep)(za)(pre)(a)(nt)(a).
Constraints
- 1 <= text.length <= 1000
- text consists of lowercase English letters
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.