---
# System prepended metadata

title: (LeetCode) 76. Minimum Window Substring

---

# (LeetCode) 76. Minimum Window Substring

https://leetcode.com/problems/minimum-window-substring/

###### Hard

##### Solution
```python=
class Solution:
    def minWindow(self, s: str, t: str) -> str:

        count = Counter(t)

        start = 0
        end = -1

        rem_start = start
        rem_end = end

        match = 0

        minSize = float('inf')

        while end < len(s) - 1:

            end += 1

            char = s[end]

            if(char in count):
                count[char] -= 1
                if(count[char] == 0 and match < len(count)):
                    match += 1


            while match == len(count):
                ms = end-start+1
                if(ms < minSize):
                    minSize = ms
                    rem_start = start
                    rem_end = end

                sc = s[start]

                if(sc in count):
                    count[sc] += 1
                    if(count[sc] > 0):
                        match -= 1

                start += 1


        return s[rem_start:rem_end+1]
```

##### Tips
* Sliding Window

