All problemsBack
Longest Palindromic Substring
mediumGiven a string s, return the longest substring which is a palindrome.
Test Cases
Copy an input into themain harness and Run to verifyInput
s = "babad"Expected Output
"bab"Explanation: "aba" is also a valid answer.
Input
s = "cbbd"Expected Output
"bb"Constraints
- 1 <= s.length <= 1000
- s consists of only digits and English letters.
Hints
Hint 1 — click to reveal
Expand around each possible center.
Hint 2 — click to reveal
A palindrome center can be a single character OR between two characters (even length).
Java Compiler
Powered by OneCompiler. Starter code loads automatically — edit and hit Run.