/5. Longest Palindromic Substring

5. Longest Palindromic Substring

Medium
Two Pointers37.4% acceptance

Given a string input_string, return the longest contiguous substring of input_string that is a palindrome. If multiple substrings of maximum length exist, return any one of them.

Example 1

Input: "racecarxyz"

Output: "racecar"

Explanation: The longest palindromic substring is racecar.

Example 2

Input: "abacdfgdcaba"

Output: "aba"

Explanation: The longest palindromic substring is aba.

Example 3

Input: "1234321abc"

Output: "1234321"

Explanation: The longest palindromic substring is 1234321.

Constraints

  • 1 <= len(input_string) <= 1000
  • input_string consists only of digits and English letters (a-z, A-Z, 0-9)
Python (current runtime)

Case 1

Input: "noonmadam"

Expected: "madam"

Case 2

Input: "abcdefg"

Expected: "a"

Case 3

Input: "xyzyxabc"

Expected: "xyzyx"

Case 4

Input: "aabbccdd"

Expected: "aa"

Case 5

Input: "abcdedcba"

Expected: "abcdedcba"