← DiffPush

Palindrome partioning

DiffPush Tier Recursion · Try Out All Combos O(n * 2^n) — up to 2^n cut plans, each checked and copied in O(n) · O(n) recursion depth beyond the output

Slicing the Transmission Log into Mirrored Blocks

A telecom archive stores telemetry strings that auditors want pre-sliced into blocks, where every block reads the same forwards and backwards. The slicer scans from the current offset, cuts at every prefix that survives the mirror test, and recurses on the remainder — recording a full slicing plan each time the string is consumed.

Input: A string s of lowercase letters.

Output: Every partition of s into palindromic substrings, each as a list of the pieces in order.

Constraints

Examples

Example 1

Input: {"s":"aab"}
Output: [["a","a","b"],["aa","b"]]
Single-letter cuts always mirror; the only multi-letter option is slicing off "aa" first.

Example 2

Input: {"s":"a"}
Output: [["a"]]
One character is its own mirror image.

Solve this in your browser →

Also on LeetCode ↗