Longest Palindromic Substring

Medium Two Pointers AI round

s is a string of letters and digits.

A palindrome reads the same from left to right as from right to left. A substring is a stretch of s taken without gaps, at least one character long. An upper case letter and its lower case are different characters.

Return the longest substring of `s` that is a palindrome. When several are equally long, any of them is right.

Example 1

Input: s = "xracecarbz"
One right answer: "racecar"

racecar reads the same both ways, and no longer stretch of s does.

Example 2

Input: s = "noonday"
One right answer: "noon"

Example 3

Input: s = "Kayak"
One right answer: "aya"

Constraints

  • 1 ≤ s.length ≤ 5000
  • s holds only English letters, upper and lower case, and digits

Watch the explanation

More Two Pointers

All Two Pointers problems