Back to Practice Dashboard
Competitive ProgrammingEasy

Palindrome Partitioning

Learn how to solve the 'Palindrome Partitioning' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Easy

Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.

Implement a function partition(s: str) -> list.

Constraints
  • 1 <= s.length <= 16
  • s contains only lowercase English letters

Examples

Example 1
Input
"aab"
Output
[["a","a","b"],["aa","b"]]
Explanation

"a","a","b" are all palindromes. "aa" is a palindrome and "b" is a palindrome. These are the only two valid partitions.

Example 2
Input
"a"
Output
[["a"]]
Explanation

A single character is always a palindrome.

Need a Hint?
Define subproblem states, establish the recurrence relation, and use memoization (top-down) or tabulation (bottom-up).
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor