Palindrome Partitioning
Problem
Given a string s, split it into a sequence of contiguous non-empty pieces such that every piece is a palindrome. Return every such split. The order of splits in the output does not matter, but the pieces within a split must appear in their original left-to-right order.
- The string is up to 14 characters (short, since the output can be exponential).
scontains only lowercase English letters.
Examples
s = "xxy"→[["x","x","y"], ["xx","y"]]."xxy"itself is not a palindrome, so the first piece is"x"or"xx".s = "x"→[["x"]].s = "noon"→[["n","o","o","n"], ["n","oo","n"], ["noon"]].
Hints
- The first piece must be a palindromic prefix. Once you choose it, what is left looks like the original problem.
- Checking whether
s[i..j]is a palindrome inside the recursion repeats the same comparisons many times. Can you answer that in O(1) after some preparation? - Backtrack on the start index, trying every palindromic end position; precompute
is_pal[i][j]with the interval DPis_pal[i][j] = s[i]==s[j] and is_pal[i+1][j-1].
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.