Find the longest contiguous substring of a given string that reads the same forward and backward.
Given a string s, return the longest contiguous substring that is a palindrome.
A palindrome is a string that reads the same from left to right and from right to left. If there are multiple answers with the same maximum length, any one of them is acceptable.
s.s.1 <= |s|Example 1
Input
s = "babad"
Output
"bab"
Explanation
"bab" and "aba" are both valid longest palindromic substrings. Either one is acceptable.
Example 2
Input
s = "cbbd"
Output
"bb"
Explanation
The longest palindromic substring is "bb".
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.