Minimum Window Substring

HardSliding Window

You are given two strings s and t. Return the shortest substring of s that contains every character of t, including repeats: if t has two as, the substring needs at least two as. Other characters may appear in the substring too.

If no such substring exists, return the empty string "". Characters are case-sensitive. If several shortest substrings exist, return any one of them.

Constraints

  • 1 <= s.length, t.length <= 10^5
  • s and t contain uppercase and lowercase English letters.
  • Aim for O(m + n) time.

Examples

Example 1

Input: s = "XAYBZCAB", t = "ABC"
Output: "CAB"

"CAB" (indices 5 to 7) contains A, B and C, and no window of 3 characters elsewhere does.

Example 2

Input: s = "abc", t = "cc"
Output: ""

t needs two c's but s has only one, so no window works: return "".

Example 3

Input: s = "AaBb", t = "ab"
Output: "aBb"

Letters are case-sensitive: the window must contain a lowercase a and a lowercase b, so the shortest is "aBb".

JavaScript you'll use: Map and Set Strings and characters

/**
 * @param {string} s
 * @param {string} t
 * @return {string}
 */
function minWindow(s, t) {
  
}

Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.