A rotated palindrome is like \"1234321\", \"3432112\". The naive method will be cut the string into different pieces and concate them back and see if the string is a palindr
Concatenate the string to itself, then do the classical palindrome research in the new string. If you find a palindrome whose length is longer or equal to the length of your original string, you know your string is a rotated palindrome.
For your example, you would do your research in 34321123432112
, finding 21123432112
, which is longer than your initial string, so it's a rotated palindrome.
EDIT: as Richard Stefanec noted, my algorithm fails on 1121
, he proposed that we change the >=
test on the length by =
.
EDIT2: it should be noted than finding a palindrome of a given size isn't obviously easy. Read the discussion under Richard Stefanec post for more information.