Neural Mastery
← Practice
Minimum Window Substringhard

Minimum Window Substring

hard Coding Interview Patterns 25–30 min

NumPy allowed · plain Python earns 10 bonus points

Interactive
Two Pointers & Sliding Window, Step by Step
Pattern
1
L
2
3
4
6
R
arr[L]=1 + arr[R]=6 = 7 vs target 6 -> too big, move R left
Step 1 / 3
Both modes run the exact algorithm described on the linked practice problem, one real step at a time -- not a pre-rendered animation. Edit the input and every step recomputes live.

Master the canonical hard sliding window: track required multi-character counts and contract the left pointer whenever the condition is satisfied.

Related Skills

Task

Implement min_window(s, t): find the shortest contiguous substring in s that contains all characters from t with their required multiplicities. If no such substring exists, return "".

Function Signature

min_window(s: str, t: str) -> str

Examples

Example 1: Classic BANC Substring
Input: s = 'ADOBECODEBANC' t = 'ABC'
Output: 'BANC'
Example 2: Single Character Match
Input: s = 'a' t = 'a'
Output: 'a'

Constraints

  • Libraries are allowed; a plain-Python solution earns 10 bonus points.
  • 1 <= len(s), len(t) <= 10^5.
  • s and t consist of uppercase and lowercase English letters.
  • Must execute in O(m + n) time.
Python3Saved ✓
def min_window(s: str, t: str) -> str:
"""Return the minimum window substring of s such that every character in t
(including duplicates) is included in the window. If there is no such
substring, return the empty string ""."""
# Your implementation here
pass

Case 1: Classic BANC Substring
Input: s = 'ADOBECODEBANC' t = 'ABC'
Expected: 'BANC'
Case 2: Single Character Match
Input: s = 'a' t = 'a'
Expected: 'a'