Skip to main content
LeetCode 76, Hard. Topics: Hash Table, String, Sliding Window. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 11 parametrized pytest cases, and a playground notebook:

Problem

Given two strings s and t of lengths m and n respectively, 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 "". The testcases will be generated such that the answer is unique.

Examples

Explanation: The minimum window substring “BANC” includes ‘A’, ‘B’, and ‘C’ from string t.
Explanation: The entire string s is the minimum window.
Explanation: Both ‘a’s from t must be included in the window. Since the largest window of s only has one ‘a’, return empty string.

Constraints

  • m == s.length
  • n == t.length
  • 1 <= m, n <= 10^5
  • s and t consist of uppercase and lowercase English letters.
Follow up: Could you find an algorithm that runs in O(m + n) time?

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Grind 75, Grind, Blind 75, NeetCode 150, NeetCode 250, NeetCode All, AlgoMaster 75.
Last modified on August 25, 2026