Minimum Window Substring

hard · sliding window

Return the shortest contiguous substring of text containing every character of required with at least its required multiplicity. Ignore no characters: comparisons are case-sensitive. If shortest windows tie, choose the smallest starting index. Return '' if required is empty or no window exists. Strings have at most 500 characters. Examples (JSON; null means Python None): Input: {"text": "ADOBECODEBANC", "required": "ABC"} Output: "BANC" Input: {"text": "aa", "required": "aa"} Output: "aa"

Starter code

def minimum_window(text: str, required: str) -> str:
    """Find the earliest minimum window covering a character multiset."""
    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

4 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. TryGetValueCharacter joke · No posting date

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

  2. TryGetValueCharacter joke · No posting date

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

  3. The GraderCharacter joke · No posting date

    Your solution is correct. Your variable names are a crime scene.

  4. TryGetValueCharacter joke · No posting date

    I found the bug. It was me. I was the bug.