Here is the implementation:
function minWindow(s, t):
required = frequency map of t
have = 0, need = required.size
window = empty map
minLen = infinity, result = ""
left = 0
for right from 0 to s.length - 1:
c = s[right]
window[c] += 1
if c in required and window[c] == required[c]:
have += 1
while have == need:
if right - left + 1 < minLen:
minLen = right - left + 1
result = s[left..right]
window[s[left]] -= 1
if s[left] in required and window[s[left]] < required[s[left]]:
have -= 1
left += 1
return result
time, space.