Problem :

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


My Solution :

class Solution:
def minWindow(self, s: str, t: str) -> str:
t_cnt = dict()
for c in t:
t_cnt[c] = t_cnt.get(c, 0) + 1
remain = len(t)
left = right = 0
ans = ''
while right < len(s):
c = s[right]
if c in t_cnt:
if t_cnt[c] > 0:
remain -= 1
t_cnt[c] -= 1
right += 1
while remain == 0:
if not ans or len(ans) > right - left:
ans = s[left:right]
c = s[left]
if c in t_cnt:
if t_cnt[c] == 0:
remain += 1
t_cnt[c] += 1
left += 1
return ans