Problem · String
Longest Palindromic Substring
Learn this problemProblem statement
Given a string text, return its longest contiguous substring that is a palindrome.
If multiple palindromic substrings have the maximum length, return the one with the smallest starting index.
Function
longestPalindromicSubstring(text: String) → StringExamples
Example 1
text = "ababc"return = "aba"Both aba and bab have length 3. The substring aba starts earlier.
Example 2
text = "cbbd"return = "bb"The longest palindromic substring is bb.
Constraints
1 <= text.length <= 2000textcontains only lowercase English letters.