#C11722. Longest Palindromic Substring
Longest Palindromic Substring
Longest Palindromic Substring
Given a string s, your task is to find the length of its longest palindromic substring. A palindromic substring is a substring which reads the same backwards as forwards.
For example, in the string babad
, one of the longest palindromic substrings is bab
(or aba
), so the answer is 3
. In racecar
, the entire string is a palindrome, and its length is 7
.
You are expected to implement an efficient algorithm to solve this problem. A common approach involves expanding around potential centers of palindromes. You might find the following formula useful when describing the expansion: if a palindrome centered at index i expands from l to r, then its length is given by \[ \text{length} = r - l - 1 \]
inputFormat
The input consists of a single line containing the string s. The string may contain letters and other printable characters. The input is provided via stdin.
outputFormat
Output the length of the longest palindromic substring in s to stdout.
## samplebabad
3