Skip to content
HardStringsAI interview only

Minimum Window Substring

Asked atmetaamazongooglemicrosoftlinkedinuberbloomberg

01 · 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.

02 · Examples

Example 01
Input
s = "ADOBECODEBANC", t = "ABC"
Output
"BANC"

The minimum window substring "BANC" (indices 9-12) contains all characters from t: 'A', 'B', and 'C'.

Example 02
Input
s = "a", t = "a"
Output
"a"

The entire string s is the smallest window that contains all characters of t.

03 · Constraints

  • 01m == s.length
  • 02n == t.length
  • 031 <= m, n <= 105
  • 04s and t consist of uppercase and lowercase English letters.

04 · Optimal complexity

Time
O(m + n)
Space
O(m + n)
05 · Two ways to work on it

Practice it alone or rehearse it as an interview.

Practice Mode gives you an editor and test runs, nothing else. AI Interview Mode puts a voice interviewer on the other side, adds a clock, and ends with a scored summary of the round.