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

Largest Palindromic Substring

MediumPython

Problem

Find the largest palindromic substring in a given string. Implement longest_palindrome(s) to return the longest contiguous substring that reads identically forward and backward. If multiple substrings have the same maximum length, return the leftmost one. The input is a string, and the output is a string.

Constraints

  • 0 <= len(s) <= 1000
  • s contains printable characters
  • Return the leftmost substring when multiple longest palindromes have equal length

Function Signature

def longest_palindrome(s):
Interviewer

Your question is Largest 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.