Loading problem…
Given a string s, return the longest palindromic substring in s.
Example 1
Input: s = babad
Output: bab
Explanation: "bab" and "aba" both read the same backwards and have length 3. No palindrome of length 4 or 5 exists, so either answer is accepted.
Example 2
Input: s = cbbd
Output: bb
Explanation: "bb" is the longest substring that reads the same forwards and backwards.
Example 3
Input: s = a
Output: a
Explanation: A single character is always a palindrome.
For each character (and each pair of characters), expand outward as long as the palindrome holds. Track the longest.
Run checks all cases above. Submit evaluates all test cases.