Longest Palindromic Substring

Medium String Manacher

Problem

Return the longest palindromic substring of a string. If there are several of the same length, any one of them is accepted.

Original: LeetCode 5: Longest Palindromic Substring.

Examples

Example 1

Input`s = "babad"`
Output`"bab"`

"aba" is also a valid answer.

Example 2

Input`s = "cbbd"`
Output`"bb"`

Constraints

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

Hints

Solution

Tried it yourself? The approach, complexity, and code stay hidden until you choose.

Sources (1)
  1. LeetCode 5: Longest Palindromic Substringleetcode.com