Palindromes · Medium
A text-analysis tool highlights the length of the longest contiguous range that reads the same in both directions. Characters cannot be rearranged or skipped. Ties need no position rule because only the length is requested.
Return the length of the longest contiguous palindromic substring without reconstructing it.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
{ text: string }
Fields
- text is an ASCII string. Case, punctuation and spaces are significant; do not normalize or trim it.
Output
Return value
- Return an integer length; empty text returns 0.
- Return a substring length, not a subsequence length or the number of palindromes.
Constraints
- 0 <= text.length <= 2000; ASCII only.
Examples
Example 1
{
"text": "xabbaq"
}Returns
4Example 2
{
"text": "Aa"
}Returns
1Required complexity
O(n^2) time and O(1) auxiliary space; faster exact approaches are also accepted