Finally, for an "interesting text" detector, the tool must find the longest stretch of a document that reads the same forwards and backwards, out of potentially a million characters. Given a string S, print the length of its longest palindromic SUBSTRING (contiguous, not subsequence). N can be up to 10^6, so an O(N^2) expand-around-center approach is too slow — implement Manacher's algorithm for O(N).
Input
One string S.
Output
Length of the longest palindromic substring.
Constraints
1 ≤ |S| ≤ 10^6
Sample Input
babad
Sample Output
3
main.c
Loading editor…
Write C, then Run (custom I/O) or Submit (sample tests). ⌘/Ctrl+Enter submits.