Here's a link
Given a string s, return the longest palindromic substring in s. A string is called a palindrome string if the reverse of that string is the same as the original string.
Example 1:
Input: s = "babad" Output: "bab" Explanation: "aba" is also a valid answer.
Example 2:
Input: s = "cbbd" Output: "bb"
from collections import defaultdict
def is_palindrome(s):
return s == s[::-1]
def solve(s):
seen = defaultdict(list)
found = ''
for i, char in enumerate(s):
if seen[char]:
for j in seen[char]:
ss = s[j : i + 1]
if is_palindrome(ss):
found = max(ss, found, key=len)
break
seen[char].append(i)
if not found:
found = s[0]
return found