#K82702. Longest Palindromic Substring Length

    ID: 36034 Type: Default 1000ms 256MiB

Longest Palindromic Substring Length

Longest Palindromic Substring Length

Given a string s, find the length of the longest contiguous substring that is a palindrome. A palindrome is a string that reads the same forwards and backwards. In this problem, you are required to determine the maximum length L such that there exists indices i and j with 0 ≤ i ≤ j < n (where n is the length of the string) for which the substring s[i...j] is a palindrome. The dynamic programming solution typically uses a state transition like \(dp[i][j]\), where \(dp[i][j] = true\) if s[i] equals s[j] and the substring s[i+1...j-1] is also a palindrome.

Your program should read the input from standard input and print the result to standard output.

inputFormat

The input consists of a single line containing the string s.

Example:

babad

outputFormat

Output a single integer representing the length of the longest palindromic substring in s.

Example:

3
## sample
babad
3