PythonStudio
Interview Problems

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 compiler