DIY: Longest Palindromic Substring

Solve the interview question "Longest Palindromic Substring" in this lesson.

Problem statement

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


The input will contain a string s. The following is an example input:



The output will be a string representing the longest palindrome. The following is an example output:


Coding exercise

Implement the longest_palindrome(s) function, where s is the string. The function returns the longest palindromic substring from s.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.