Paths Subjects Questions Quizzes Pricing Search
Intermediate Open Pro

Longest Palindrome in a String

Given a string s, return the longest substring of s that is a palindrome (reads the same forwards and backwards). If there are multiple longest palindromic substrings, return any one of them.

Example 1

Input: s = "babad"
Output: "bab"
Explanation: "aba" is also a valid answer.

Example 2

Input: s = "cbbd"
Output: "bb"

Constraints

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

Share this question

← Back to Dynamic Programming practice

We use cookies for product analytics to improve OmniAtlas. See our Privacy Policy.