Code Room
CodingMediumcod-g151
Subject PalindromesLevel Mid–Senior~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.