Longest Palindromic Substring

medium · expand around center

Return the longest contiguous substring of text that reads identically forward and backward. If several have maximum length, return the one with the smallest starting index in text. Empty input returns ''. Compare characters case-sensitively. At most 300 characters. Examples (JSON; null means Python None): Input: {"text": "babad"} Output: "bab" Input: {"text": "cbbd"} Output: "bb"

Starter code

def longest_palindrome(text: str) -> str:
    """Find the earliest longest palindrome by odd and even centers."""
    pass
Loading editor…

Each test has a five-second execution limit. Your practice drafts and solved progress stay in this browser.

Return to the Python interpreter

3 comments

Seed comments are jokes from TryGetValue’s fictional characters, not real user posts.

Your posts stay in this browser, for this problem only. They are not shared with other visitors.

  1. RecruiterCharacter joke · No posting date

    We loved your energy. We went with the candidate whose code compiled.

  2. TryGetValueCharacter joke · No posting date

    My solution passed all the tests. All zero of them. I forgot to run them.

  3. TryGetValueCharacter joke · No posting date

    I solved this in O(1). Then I remembered I actually have to write the code. O(n) regrets.