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

Longest Palindromic Substring

MediumPython

Problem

Given a string, return the longest palindromic substring. Implement def longest_palindrome(s):, returning a string. A palindrome reads identically from left to right and right to left. If multiple palindromic substrings have the same maximum length, return the one that appears first.

Constraints

  • 0 <= len(s) <= 1000
  • s contains printable ASCII characters
  • Return the earliest substring when multiple answers have the same maximum length

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.