A palindrome reads the same forwards and backwards. Find the longest stretch of consecutive characters in s that is a palindrome, and return that stretch. If several palindromes tie for the greatest length, return the one that starts first.
Example 1
Input
s = "mopqqponrs"
Output
"opqqpo"
Explanation
opqqpo reads the same in both directions, and no longer stretch of s does.
Example 2
Input
s = "xabaycdcz"
Output
"aba"
Explanation
aba and cdc are both palindromes of length 3, the longest there is. The tie goes to aba, which starts first.
Constraints:
1 <= s.length <= 1000
lowercase English letters only
Tab indents. Press Esc, then Tab to leave the editor.
Ctrl or ⌘ + Enter runs the tests.
Run your code to see every test here. Nothing is submitted or recorded.