Palindrome Partitioning - Problem
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.
A palindrome is a string that reads the same backward as forward.
Input & Output
Example 1 — Basic Case
$
Input:
s = "aab"
›
Output:
[["a","a","b"],["aa","b"]]
💡 Note:
"a" and "aa" are palindromes, "b" is palindrome. Two valid partitions: split each character separately ["a","a","b"] or group first two ["aa","b"].
Example 2 — All Partitions
$
Input:
s = "raceacar"
›
Output:
[["r","a","c","e","a","c","a","r"],["r","a","c","e","aca","r"],["r","ace","ca","r"],["race","a","car"],["raceacar"]]
💡 Note:
Multiple palindromes possible: single chars, "aca", "raceacar" (whole string), etc.
Example 3 — Single Character
$
Input:
s = "a"
›
Output:
[["a"]]
💡 Note:
Single character is always a palindrome, only one partition possible.
Constraints
- 1 ≤ s.length ≤ 16
- s contains only lowercase English letters
Visualization
Tap to expand
Understanding the Visualization
1
Input
String to be partitioned: "aab"
2
Process
Find all ways to split into palindromes
3
Output
All valid palindrome partitions
Key Takeaway
🎯 Key Insight: Use backtracking to build partitions incrementally, only exploring palindromic substrings
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code