Medium · Strings

Longest palindromic substring

Given a string s, return the longest substring of s that is a palindrome (reads the same forwards and backwards); if several substrings share the maximum length, any one of them is accepted.

Examples

Example 1

{
  "s": "babad"
}

Output: "bab" (len 3)

Example 2

{
  "s": "cbbd"
}

Output: "bb" (len 2)

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Strings problems