29. Palindrome Partitioning

29. Palindrome Partitioning

Medium
47.0%
1.3k
stringdynamic-programmingrecursionbacktracking
The output size can be large, so focus on correctness and pruning.

You’re interviewing for a backend or data engineering role at a FAANG-level company. The interviewer describes a real product scenario:

A large content analysis platform processes text data to detect symmetric patterns and to generate segmentation candidates for downstream tasks like:

  • searchable phrase indexing
  • content fingerprinting
  • template detection
  • NLP token chunking for recommendations

The platform receives a string s. For a given string, the system wants to generate all valid ways to split the string into parts where each part is a palindrome. This helps in building candidate phrase boundaries where each segment is structurally symmetric.

This is a common practice coding problem for DSA question might ask in Google, Amazon, Netflix, Meta, Apple, Microsoft, Uber, and Bloomberg interviews.

Your Task

Given a string s, return all possible palindrome partitioning of s.

A partition is defined as splitting the string into one or more substrings such that each substring is a palindrome.

Return the result as a list of lists of strings.

Input Format

  • s: a string

Output Format

  • A list of lists of strings representing all palindrome partitions

Examples

Example 1:

Input: s = "aab"
Output: [["a","a","b"],["aa","b"]]

Example 2:

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

Constraints

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

Loading editor...

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

Console Output

Click "Run Code" or "Submit" to see results

Your code will be evaluated by AI with instant feedback