Longest Palindromic Substring

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

A substring is a contiguous sequence of characters within a string. A palindrome is a string that reads the same forward and backward.

If there are multiple valid longest palindromic substrings, you may return any one of them.

Example 1
Inputs = "babad"
Output"bab"
The substring bab reads the same forward and backward and has maximum length; aba is also a valid answer.
Example 2
Inputs = "cbbd"
Output"bb"
The longest palindromic substring is bb.

Constraints

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

Asked at 74 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate