Top 150 InterviewEasy

Palindrome Partitioning

Detailed guide and Python implementation for the 'Palindrome Partitioning' problem.

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?
Consider using Backtracking-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

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

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.