#K4781. Longest Palindromic Substring Length
Longest Palindromic Substring Length
Longest Palindromic Substring Length
You are given a string s
of length n
. Your task is to find the length of the longest substring of s
that is a palindrome.
A palindrome is a string that reads the same backward as forward. In mathematical terms, a substring s[i...j]
is palindromic if for all indices \( k \) satisfying \( 0 \leq k \leq j-i \), the following holds:
\( s[i+k] = s[j-k] \)
For example, if s = "abba"
, the whole string is a palindrome with length 4, and if s = "abc"
, the longest palindromic substring is any single character with length 1.
Implement an efficient solution to determine the maximum length of a palindromic substring in the given string.
inputFormat
The input is read from standard input (stdin
) and consists of two lines:
- The first line contains an integer
n
, which is the length of the string. - The second line contains the string
s
of lengthn
.
outputFormat
Print a single integer to standard output (stdout
), which is the length of the longest palindromic substring of s
.
4
abba
4
</p>