Dynamic Programming21 sections · 916 units
Open in Course

Challenge: Palindrome Partitioning All

Finding all partitions

The DP gives minimum cuts. What about finding all palindrome partitions? Use backtracking with the isPalinisPalin table. At each position, try all palindromic prefixes.

For "aab": start at 00. "a" is palindrome → recurse on "ab". "aa" is palindrome → recurse on "b". "aab" is not. Collect all valid partitions: [["a", "a", "b"], ["aa", "b"]]. Time: exponential in worst case. The time complexity is exponential because the number of valid partitions can be exponential.