For a string of length N containing the characters [AZ], how to determine the longest palindrome for a single character?
I will illustrate this with an example:
The specified string: JOHNOLSON When analyzing the string, we find that we have a palindrome with the character O , so that the string looks like J O HN O LS O N The palindrome for O has a length of 7, essentially looking like O -- O -- O Also note that there is a palindrome with N , but it has a length of 6.
Another example, This line: ABCJOHNOLSON gives the same result as above, with an O palindrome of length 7, similar to O -- O -- O
However, with this line ABCJOHNOLSONDA , the longest individual palindrome has a length of 14 with a character A similar to A ------------ A
Other simple examples include:
ABA → A - A (length 3)
ABAXYZ → A - A (length 3)
ABAXYZA → A --- A (length 5), not length 7, because A - A --- A not a palindrome for the letter A
Pay particular attention to the last example, because it illustrates one of the subtle nuances of the problem.
algorithm palindrome
jbranchaud
source share