Given a string s, your task is to partition it into substrings such that every substring in the partition is a palindrome. A palindrome reads the same forwards and backwards, like "racecar" or "aba".
You need to return all possible palindrome partitionings of the string. Think of it as finding every way to "cut" the string into pieces where each piece is a palindrome.
Example: For string "aab":
โข One partitioning: ["a", "a", "b"] - each single character is a palindrome
โข Another partitioning: ["aa", "b"] - "aa" is a palindrome, "b" is a palindrome
The challenge is to find all such valid partitionings efficiently!
Input & Output
Visualization
Time & Space Complexity
O(Nยฒ) for building DP table to check all substrings, plus O(2^N) for generating all possible partitions
O(Nยฒ) for the DP table storing palindrome information, plus O(N) recursion stack
Constraints
- 1 โค s.length โค 16
- s contains only lowercase English letters
- Note: The relatively small constraint on length makes backtracking feasible