ntree.ai
ntree.aiMinimum Window Substring

Minimum Window Substring

hardsolvedattempted

Given two strings s and t, return the shortest substring of s that contains every character of t.

If no such substring exists, return the empty string "". Whenever an answer exists, it is unique.

Example 1:

Input:  s = "ADOBECODEBANC", t = "ABC"
Output: "BANC"
Explanation: "BANC" has an A, a B and a C.

Example 2:

Input:  s = "a", t = "aa"
Output: ""
Explanation: t needs two a's, but s has only one.

Constraints:

  • 1 <= length of s, length of t <= 10^5
  • s and t have English letters only
def minWindow(s: str, t: str) -> str:
pass
 

Press Visualise to step through your code.