Back to DSA
Longest Palindromic Substring
mediumFor a given string, find and return the longest substring that reads the same forwards and backwards. If multiple substrings share the maximum length, any one of them is acceptable.
Examples
Example 1:
Input:
s = "racecar"Output:
"racecar"Explanation: The entire string is a palindrome.
Example 2:
Input:
s = "abcda"Output:
"a"Explanation: No multi-character palindromic substring exists, so any single character is valid.
Hints
1234567