Given a string l
, find all palindromic substrings p
of l
(including duplicates and single character strings). Next, rearrange all sub-strings in p
into a valid palindrome (there may be multiple correct answers). If it is not possible to rearrange p
into a single palindrome, your program may have undefined behavior (error, stack-overflow, exiting, hanging/untimely murder of John Dvorak, etc...)
Examples
Valid Test Cases
l = anaa
p = ['a', 'n', 'a', 'a', 'aa', 'ana']
result = anaaaaana or aanaaanaa or aaananaaa
l = 1213235
p = ['1', '2', '1', '3', '2', '3', '5', '121', '323']
result = 1213235323121
l = racecar
p = ['r', 'a', 'c', 'e', 'c', 'a', 'r', 'cec', 'aceca', 'racecar']
result = racecarcecaacecracecar (there are others)
l = 11233
p = ['1', '11', '1', '2', '3', '33', '3']
result = 113323311 or 331121133
l = abbccdd
p = ['a', 'b', 'bb', 'b', 'c', 'cc', 'c', 'd', 'dd', 'd']
result = bbccddaddccbb or ccbbddaddbbcc or (etc...)
l = a
p = ['a']
result = a
Invalid Test Cases (Not Possible)
l = 123456789
p = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
result = <not possible, behavior undefined>
l = hjjkl
p = ['h', 'j', 'jj', 'j', 'k', 'l']
result = <not possible, behavior undefined>
l = xjmjj
p = ['x', 'j', 'jmj', 'm', 'j', 'jj', 'j']
result = <not possible, behavior undefined>
Rules
- If the input word is a palindrome itself, it will always be valid as input.
- Only one substring should be returned, which one you choose is arbitrary as long as it's valid.
- If the input has no viable output, your code may have undefined behavior.
- Inputs will only contain ASCII-Printable characters between
0x20-0x7E
. - This is code-golf, lowest byte-count is the winner.
"abbccdd"
is wrong: the last two letters should be"bb"
, not"dd"
. \$\endgroup\$