Back to Practice
#0235

Minimum Window Substring

HardDSA40 min25 XP

Problem

Given strings s and t, return the smallest substring of s containing every character of t with required multiplicity. Return an empty string if no window exists.

Why This Matters

Minimum window is the advanced sliding-window pattern: expand until valid, then shrink while still valid.

Function Signature

def min_window(s, t):

Examples

Example 1
Inputs = "ADOBECODEBANC", t = "ABC"
Output"BANC"

BANC is the shortest substring containing A, B, and C.

Constraints

  • Return the exact requested value.
  • Handle empty or small inputs when the prompt allows them.
  • Prefer the target DSA pattern over brute force when the input can grow.
CodePython
Visible browser tests run here when available.
Testcases2 visible / 3 hidden categories
Classic window
Inputs = "ADOBECODEBANC", t = "ABC"
Expected"BANC"

The final valid window is shortest.

Repeated requirement
Inputs = "AAABBC", t = "AABC"
Expected"AABBC"

The target needs two As, one B, and one C.

Hidden Test Categories
no valid windowsingle-character targettarget longer than source