DSA · Strings · #126
Minimum Window Substring
Module 62 · difficulty 4/5·⏱ 30:00starts on first keystroke
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 substring, return the empty string `""`. The answer is guaranteed to be **unique**. Implement `minWindow(s, t)` which returns the substring (a `string`).
Examples
s = "ADOBECODEBANC", t = "ABC"→"BANC"— The minimum window "BANC" contains A, B, and C from t.s = "a", t = "a"→"a"— The entire string s is the minimum window.s = "a", t = "aa"→""— Two 'a's must be included in t, but s has only one, so no valid window exists.
Constraints
- · 1 <= s.length, t.length <= 10^5
- · s and t consist of uppercase and lowercase English letters.
- · The answer is unique when it exists.
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.