v9.1.1
Menu

Longest Palindromic Substring

mediumFREEDynamic ProgrammingBlind 75

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

More from Blind 75

solution.py

Test results

Sign in to run your code against the test cases.