Longest Palindromic Substring
You get a string. Find its longest piece of consecutive characters that reads the same left to right and right to left. Our example: "xabbay" — the answer is "abba".
- input
s: a string of letters and digits.- returns
- The longest substring of
sthat reads the same both ways, uppercase and lowercase letters being different. If several are the longest, any one of them. - constraints
- 1 ≤ s.length ≤ 1000
- s: English letters and digits
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {string} s
* @return {string}
*/
function longestPalindrome(s) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more two pointers problems
- 125Valid PalindromeEasysolve
- 26Remove Duplicates from Sorted ArrayEasysolve
- 283Move ZeroesEasysolve
- 88Merge Sorted ArrayEasysolve
- 27Remove ElementEasysolve
- 392Is SubsequenceEasysolve
- 167Two Sum II - Input Array Is SortedMediumsolve
- 153SumMediumsolve
- 11Container With Most WaterMediumsolve
- 80Remove Duplicates from Sorted Array IIMediumsolve
- 189Rotate ArrayMediumsolve
- 151Reverse Words in a StringMediumsolve
- 42Trapping Rain WaterHardsolve
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.