Skip to content
Onsite

Palindrome Partitioning

MediumP2Coding

Split s into consecutive pieces so that every piece is a palindrome. Return every possible split, in any order. Each split is an array of the pieces in the order they appear in s.

Example 1

Input
s = "aab"
Output
[["a","a","b"],["aa","b"]]
Why
Two valid splits: all single letters, or aa + b.

Example 2

Input
s = "a"
Output
[["a"]]

Example 3

Input
s = "aa"
Output
[["a","a"],["aa"]]

Constraints

  • 1 <= s.length <= 12
  • s contains lowercase English letters.

Hints

Run checks the 3 visible tests, Submit all 10.