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
Palindrome Partitioning: "aab" → All Palindromic SplitsaabInput StringFind All PartitionsValid Partitions1. ["a", "a", "b"]2. ["aa", "b"]Palindrome Check Examples"a" ✓"aa" ✓"b" ✓"aab" ✗Result: 2 valid palindrome partitionsEach substring in the partition must read the same forwards and backwards
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
Asked in
Amazon 45 Microsoft 38 Google 32 Facebook 28
87.5K Views
High Frequency
~25 min Avg. Time
2.8K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen