Problem Statement: Palindrome Chain Transformer
You are given a list of strings. For each string, transform it into a palindrome by appending the minimum number of characters to its end. If a string is already a palindrome, leave it as is.
Once all strings are transformed, compress the transformed list into a "Palindrome Chain Representation" as follows:
- For the first occurrence of a palindrome, retain the entire palindrome string.
- For subsequent occurrences of the same palindrome, replace it with the index (0-based) of its first occurrence in the transformed list.
Write a program to process the input strings, generate the transformed palindromes, and return the compressed representation.
Input Format
A single line containing space-separated strings.
- Each string consists of 1 to 20 lowercase English letters.
- There are 1 to strings.
Output Format
A single line containing space-separated values representing the "Palindrome Chain Representation."
- The output can contain transformed palindromes or indices (0-based).
Constraints
- Strings are case-sensitive.
- The number of strings will not exceed .
Sample Test Cases
Sample Input 1
Sample Output 1
Sample Input 2
Sample Output 2
Sample Input 3
Sample Output 3
Explanation of Sample Test Cases
In Sample Input 1:
- Transformations:
abc
becomesabccba
.racecar
is already a palindrome.abba
is already a palindrome.car
becomescarac
.abcba
is already a palindrome.ab
becomesabba
.
- Compression:
- The first occurrences of palindromes (
abccba
,racecar
,abba
,carac
,abcba
) are retained. - Subsequent occurrences (
racecar
,abba
) are replaced by their first occurrence indices:1
forracecar
and2
forabba
.
- The first occurrences of palindromes (
- Transformations:
In Sample Input 2:
- Transformations:
aaa
,bbb
, andccc
are already palindromes.
- Compression:
- The first occurrences of palindromes (
aaa
,bbb
,ccc
) are retained. - Subsequent occurrences (
aaa
,ccc
) are replaced by their first occurrence indices.
- The first occurrences of palindromes (
- Transformations:
In Sample Input 3:
- All strings are unique palindromes after transformation, so no compression is needed.
Comments
Post a Comment