Asked at

Longest Palindromic Substring

Medium
Verified
Two PointersDynamic ProgrammingString~25 min

Given a string s, return a longest palindromic substring. Any one of the longest is acceptable.

Expand around each center (single char and each gap) and keep the widest palindrome.

The input arrives as a single string s.

Examples

in"babad"
out"bab"

"aba" is also a valid answer of the same length.

in"cbbd"
out"bb"

The longest palindrome is bb.

Constraints

  • 1 ≤ s.length ≤ 1000
  • s consists of digits and English letters.

Get help

🔑

Sign in to solve

Sign in to write, run, and submit your solution — and to pick up where your iOS flow left off.