Skip to content
Onsite

Longest Palindromic Substring

MediumP1Coding

Given a string s, return its longest palindromic substring. If several palindromic substrings share the maximum length, return the one that starts earliest.

Example 1

Input
s = "babad"
Output
"bab"
Why
"aba" is equally long, but "bab" starts earlier.

Example 2

Input
s = "cbbd"
Output
"bb"

Example 3

Input
s = "a"
Output
"a"

Constraints

  • 1 <= s.length <= 1000
  • s consists of digits and English letters.

Hints

Run checks the 3 visible tests, Submit all 8.