Back to Practice
#0266

Palindrome Partitioning

MediumDSA28 min20 XP

Problem

Return all partitions of s where every substring in each partition is a palindrome.

Why This Matters

This problem teaches backtracking over cut positions, not just over array indexes.

Function Signature

def palindrome_partitions(s):

Examples

Example 1
Inputs = "aab"
Output[["a", "a", "b"], ["aa", "b"]]

Both a|a|b and aa|b use only palindrome pieces.

Constraints

  • Return the exact requested value.
  • Handle edge cases cleanly.
  • Use the intended DSA pattern when brute force would scale poorly.
CodePython
Visible browser tests run here when available.
Testcases2 visible / 3 hidden categories
Two partitions
Input"aab"
Expected[["a", "a", "b"], ["aa", "b"]]

The prefix aa is also a palindrome.

Single character
Input"x"
Expected[["x"]]

A one-character string has one partition.

Hidden Test Categories
all same lettersno multi-character palindromesempty string behavior