Search⌘ K
AI Features

Longest Palindromic Substring

Explore methods to identify the longest palindromic substring within a given string. Understand pointer techniques for both odd and even length palindromes, and implement a solution that handles all cases with optimal time and space complexity.

Statement

Given a string of characters, find and return the longest palindromicA palindrome is a sequence of characters that reads the same backwards as forwards, for example, racecar. substring within the input string.

Examples

Example 1

Sample input

"bccd"

Expected output

"cc"

Example 2

Sample input

xaabacxcabaaxcabaax

Expected output

xaabacxcabaax

Try it yourself

#include <iostream>
using namespace std;
string LongestPalindromicSubstring(string s) {
// TODO: WRITE - CODE - HERE
return "-1";
}

Solution

There can be multiple palindromes in the input ...