Given a string S, identify the longest palindromic substring within S. A palindromic substring is defined as a sequence of characters within S that reads the same forwards and backwards. For example, "racecar" and "level" are palindromic substrings.
Example 1
Input: "abaxyzzyxf"
Output: "xyzzyx"
Explanation: The longest palindromic substring is "xyzzyx" of length 6.
Example 2
Input: "bananas"
Output: "anana"
Explanation: The longest palindromic substring is "anana" of length 5.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
abaxyzzyxf
xyzzyx
bananas
anana
aaaabbaa
aabbaa