Code RoomLongest palindromic substring
MediumPrep Room Coding #715

Longest palindromic substring

CodingAlgorithms & data structuresMid–Senior~30 min

Return the longest contiguous palindromic substring of s. If several have the maximum length, return the one that starts at the earliest index. For the empty string return the empty string. For example "babad" returns "bab" (the earliest-starting of the two length-3 answers). Strings can be up to ~1000 characters; an O(n^2) expand-around-center solution is acceptable.

Implement
longest_palindrome(s: str) → str
Examples
in["babad"]out"bab"
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 30 min
InputExpectedGot
["babad"]"bab"not run yetsample