class Solution {
public:
unordered_map<char, int> mp1;
unordered_map<char, int> mp2;
bool check() {
for (auto& c : mp1) {
if (c.second > mp2[c.first])
return false;
}
return true;
}
string minWindow(string s, string t) {
int n = s.size(), m = t.size();
int res = INT_MAX;
int l = 0, r = 0;
for (auto& e : t)
mp1[e]++;
int start = -1;
while (r < n) {
if (mp1.find(s[r]) != mp1.end())
mp2[s[r]]++;
while (check() && l <= r) {
if (r - l + 1 < res) {
start = l;
res = r - l + 1;
}
if (mp1.find(s[l]) != mp1.end())
mp2[s[l]]--;
++l;
}
++r;
}
return start == -1 ? "" : s.substr(start, res);
}
};