ALG-M011MediumTwo Pointers
Longest Mirrored Segment
Return the longest contiguous palindromic substring of text. If multiple have the same maximum length, return the one with the smallest starting index.
Contract
input text: string
return string
Constraints
- • 0 <= text length <= 1000
Examples
Example 1
text = "babad"
→ "bab"
Example 2
text = "cbbd"
→ "bb"
5 judge tests (2 shown above). Target complexity: O(n^2).