Skip to content

Palindrome Partitioning

MediumBacktracking
Decode it first. Clues, constraints, pattern and plan before any code.

Given a string s, split it into pieces so that every piece is a palindrome (reads the same forwards and backwards). Return all possible ways to do this. Each way is a list of the pieces in order. Return the ways in any order.

"aab"  →  [["a", "a", "b"], ["aa", "b"]]
"a"    →  [["a"]]

Constraints

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