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"]]
💡 Note:
The string contains the palindrome "aca" at positions 4-6. Two valid partitions: split each character separately or group the "aca" palindrome.
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
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code