Skip to main content

Minimum Window Substring

Find minimum window substring containing all characters from t Example: s = "ADOBECODEBANC", t = "ABC" => "BANC"

Minimum Window Substring is the sliding window pattern: grow, shrink, and maintain just enough state to stay linear. It's a hard one for a reason: it stresses stateful scanning when the rules pile up. Once your window update rules are consistent, you get linear time almost for free.

Examples

You write

min_window(s: str, t: str)

  1. Example 1

    Input
    s = "ADOBECODEBANC", t = "ABC"
    returns
    "BANC"
  2. Example 2

    Input
    s = "a", t = "a"
    returns
    "a"

The pattern behind it

Arrays & Hashing

I reach for it when

  • You catch yourself scanning the array again for every element.
  • The problem asks about duplicates, pairs, counts or groups.

Say this before you type. Say what the key is and what the value remembers, before you write the loop.

All 127 Arrays & Hashing problems

Sliding Window

I reach for it when

  • The question asks for the longest, shortest or best stretch of a sequence.
  • A rule like "at most k" or "no repeats" decides what counts as valid.

Say this before you type. Say what makes the window valid, and what you do to the left edge when it breaks.

All 9 Sliding Window problems

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.

1Part 1: Minimum Window Substringhard
2Part 2
3Part 3

Each locked part opens in the editor once the part before it passes.

Prep guides that list this problem

Our company tags come from public interview write-ups. None of these is a confirmed question.