Longest Palindromic Substring

Medium

Given a string s, return the longest palindromic substring in s.

If there are multiple, returning any one of them is accepted — but the tests here expect the leftmost longest one, which the expand-around-centre approach produces.

Example 1

longestPalindrome()
Input
s = "babad"
Output
"bab"

Why

"aba" is also a valid answer.

Example 2

longestPalindrome()
Input
s = "cbbd"
Output
"bb"
Constraints
1 <= s.length <= 1000
s consists of digits and English letters.

Topics

StringsDynamic Programming

Implement longestPalindrome in the editor and return the answer — printing it is never graded.