Longest Palindromic Substring
View as PDFA palindrome is a sequence of characters such that it is the same when read forwards and backwards. For instance, BOB, RACECAR are palindromes, but BRIAN is not.
You are to write a program that finds the longest palindrome in a given string of characters.
Input Specification
The first line of input will contain one positive integer , the number of characters in the string. The next line will contain a string of length
. The input string will contain only lower case alphabetical characters.
Output Specification
Your program should output a single integer, containing the length of the longest palindrome contained in the original string.
Sample Input 1
8
bcabcbac
Sample Output 1
5
Explanation of Sample Output 1
The longest palindromic substring is abcba.
Sample Input 2
7
racecar
Sample Output 2
7
Sample Input 3
7
jeffrey
Sample Output 3
2
Comments