211. Longest Palindromic Substring

MediumStringString

Given a string s, return the longest palindromic substring. If multiple have the same maximum length, return the one that appears first (leftmost).

Input: A quoted string s.

Output: Quoted string — the longest palindromic substring.

Examples

Example 1
Input: "babad"
Output: "bab"
Explanation: 'bab' is a valid longest palindrome (leftmost).
Example 2
Input: "cbbd"
Output: "bb"
Explanation: 'bb' length 2.
Example 3
Input: "a"
Output: "a"
Explanation: Single char.

Constraints

Asked by

MicrosoftCognizantBloombergAmazonDeloitteIBM
Solve this problem in the editor →