You are given a single string s. Find the length of the longest contiguous block (substring) of s that reads the same forwards and backwards.
Line 1: the string s (may be empty, producing a blank line).
s contains only lowercase English letters.
A single integer: the length of the longest palindromic substring of s.
Example 1
Input
babad
Expected
3
Explanation
"bab" (positions 0-2) and "aba" (positions 1-3) are both palindromic substrings of length 3, and no longer palindrome exists, so the answer is 3.
Example 2
Input
abba
Expected
4
Explanation
The whole string "abba" reads the same forwards and backwards, so the answer is 4.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →