Problems > The Longest Palindrome, Fast

The Longest Palindrome, Fast

Difficulty: 2000 6000 ms 128 MB

strings manacher

Print the length of the longest palindromic substring of S. |S| can be up to a million, so O(n²) center-expansion is too slow.

Input: one line with the string S.

Output: the longest palindromic substring length.

Constraints:

  • 1 ≤ |S| ≤ 106
  • lowercase letters

Sample Tests

Input 1
babad
Output 1
3
Input 2
cbbd
Output 2
2

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.