214. Minimum Window Substring

MediumStringString

Given strings s and t, return the minimum window substring of s that contains all characters of t (including duplicates). If no such window exists, return the empty string. If multiple windows tie on length, return the leftmost. Input: '"s", "t"'.

Input: '"s", "t"'.

Output: Quoted string — minimum window or empty.

Examples

Example 1
Input: "ADOBECODEBANC", "ABC"
Output: "BANC"
Explanation: Smallest window containing A,B,C.
Example 2
Input: "a", "a"
Output: "a"
Explanation: Whole string.
Example 3
Input: "a", "aa"
Output: ""
Explanation: Not enough a's.

Constraints

Asked by

AdobeMetaSwiggyAmazonMicrosoftIBM
Solve this problem in the editor →