FrontendInterviews.dev

Loading problem…

37. Minimum Window Substring

Hard•
Acceptance: 70.00%
•
🔓3/3 Pro unlocks today

You're building a search feature that needs to find the minimum window in a string containing all characters from another string. This is useful for substring matching and search optimization.

Given two strings s and t, 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 window, return the empty string "".

Requirements

1. Basic Functionality

  • Find minimum window containing all characters from t
  • Window must contain all characters (including duplicates)
  • Return minimum length window
  • Return empty string if no valid window

Example Usage

minWindow("ADOBECODEBANC", "ABC"); // "BANC"
// Minimum window containing A, B, and C

minWindow("a", "a"); // "a"
minWindow("a", "aa"); // ""

Real-World Context

This problem models real search scenarios:

  • Substring matching: Find minimum window with all characters
  • Search optimization: Efficient substring search
  • Pattern matching: Advanced pattern matching
  • Text processing: Minimum window extraction

Constraints

  • 1 <= s.length, t.length <= 10^5
  • s and t consist of uppercase and lowercase English letters
  • Return minimum length window