Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Longest Palindromic Substring
00:00
5 left

Longest Palindromic Substring

MediumPython

Problem

Find the longest palindromic substring within a given string.

Implement longest_palindrome(s) to return one longest palindromic substring. If multiple substrings have the same maximum length, return the one whose starting index is smallest. Return an empty string when s is empty.

Constraints

  • 0 <= len(s) <= 1000
  • s contains printable characters
  • Return one longest palindromic substring
  • If multiple answers have the same length, return the one with the smallest starting index

Function Signature

def longest_palindrome(s):
Interviewer

Your question is Longest Palindromic Substring. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.