Palindrome Partitioning

Practice this coding question on Coding Gurukul.

Problem statement

An archive splits a label into consecutive symmetric pieces for a decorative index. Several different cut positions may work, and the archivist wants every valid split. Your task Partition the entire input string into nonempty substrings such that every substring is a palindrome. Important details Keep the original character order and use every character exactly once. A palindrome reads identically forward and backward; a single letter qualifies. Represent each partition by joining its pieces with |. Sort these complete encoded lines by ASCII lexicographic order: lowercase letters precede |. Do not sort the pieces inside a partition. Worked example For aba, the valid partitions are aba and a|b|a. The encoded line aba sorts before a|b|a because b precedes |. Print 2 followed by those two lines.

Input format

One nonempty lowercase English string.

Output format

Print the partition count, then each | separated partition on its own line in the specified order.

Constraints

1 <= string length <= 10.

Sample input

aba

Sample output

2
aba
a|b|a

Sign in to run or submit a solution in C++, Java or Python.

Loading Coding Gurukul…