Skip to content
CodeShare
All problems

Longest Palindromic Substring

Find the longest part of a string that reads the same backward.

MediumStringsDynamic programming

Given a string s, return its longest palindromic substring: the longest run of consecutive characters that reads the same forward and backward.

Every test has exactly one answer.

Examples

Example 1
Input
s = "cbbd"
Output
"bb"
Example 2
Input
s = "forgeeksskeegfor"
Output
"geeksskeeg"
Example 3
Input
s = "a"
Output
"a"

Constraints

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