PIXELBANKv8.2.1
Menu

Longest Palindromic Substring

Given a string s, return the longest palindromic substring in s.

Example:

Input:
babad
Output:
bab
Reasoning:
  • The input string s is babad, and we need to find the longest palindromic substring in it.
  • We check for palindromes centered at each character in the string, considering both odd-length and even-length palindromes.
  • The longest palindromic substrings found are bab and aba, both with a length of 33.
  • Since both bab and aba are the longest palindromic substrings, the function can return either one, and in this case, it returns bab.

Constraints:

  • 1 <= len(s) <= 1000
  • s consists of digits and English letters
Editor

Test Results

0/0
Run code to see test results.