mediumDynamic Programming 2DPure DSA~30 min
Longest Mirror (Palindromic) Token Substring
Given a token stream rendered as a string, find the longest contiguous fragment that reads identically forwards and backwards — useful for detecting symmetric markers in serialized payloads.
Problem
Given a string s, return the longest substring of s that is a palindrome. If several have the same maximum length, return any one of them.
Input
A string s of length [1, 1000] of arbitrary characters.
Output
A string: a longest palindromic substring of s.
Constraints
- 1 <= s.length <= 1000
- s consists of printable characters.
Examples
Example 1
Input
s = "babad"
Output
"bab"
"aba" is also a valid answer of the same length.
Example 2
Input
s = "cbbd"
Output
"bb"
The longest palindrome is the pair bb.