/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 there are multiple substrings of maximum length, return any one of them.

Example 1

Input: "abacdfgdcaba"

Output: "aba"

Explanation: The longest palindromic substring is "aba" at the start and end. Either is valid.

Example 2

Input: "xyzzyxabc"

Output: "xyzzyx"

Explanation: The longest palindromic substring is "xyzzyx".

Example 3

Input: "12321abcd"

Output: "12321"

Explanation: The longest palindromic substring is "12321".

Constraints

  • 1 <= len(input_string) <= 1000
  • input_string consists only of English letters and digits
Python (current runtime)

Case 1

Input: "racecarxyz"

Expected: "racecar"

Case 2

Input: "abcdedcba"

Expected: "abcdedcba"

Case 3

Input: "aabbccdd"

Expected: "aa"

Case 4

Input: "noonmadam"

Expected: "noon"

Case 5

Input: "abcbaabcbabcba"

Expected: "abcbaabcbabcba"