15% off all plans & roadmaps Use code
See plansLeetCode 132 · Solution & editorial
Given a string s, partition s such that every substring of the partition is a palindrome.
Palindrome Partitioning II is a Backtracking Patterns problem, in the Palindrome Partitioning subpattern. The pattern covers subsets, permutations, combinations, N-Queens, and word search
Partition string into palindromic substrings using backtracking.
The reference solution runs in O(n) time and O(1) space.
Palindrome Partitioning II has been reported in interviews at Amazon, Google.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Palindrome Partitioning II is a Backtracking Patterns problem, in the Palindrome Partitioning subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.