Longest Palindromic Substring

Medium 28.9%

Description

Given a string s, return the longest palindromic substring in s.

Example 1:

Input: s = "babad"

Output: "bab"

Explanation: "aba" is also valid; either is acceptable depending on implementation.

Example 2:

Input: s = "cbbd"

Output: "bb"

Note:

Print only the final output (a substring) so it can be compared with the expected result.

  • Python: print(longestPalindrome("babad"))
  • JavaScript: console.log(longestPalindrome("babad"))
  • C++: cout << result << endl;
  • Java: System.out.println(result);

Your Submissions

No submissions yet.

Discuss

Share approaches (expand-around-center, DP, Manacher), compare runtimes, and discuss edge cases.

Test Cases

Test Case 1
Test Case 2
Test Case 3