O( n )✅ | C++ (Step by step explanation)✅
Intuition\nThe problem requires finding the minimum window in string \'s\' that contains all characters from string \'t\'. We can use a sliding window approach 
# Intuition\nThe problem requires finding the minimum window in string \'s\' that contains all characters from string \'t\'. We can use a sliding window approach to solve this problem efficiently.\n\n# Approach\n1. First, we handle the edge case: if \'t\' is an empty string, we return an empty string as the result.\n\n2. We initialize two dictionaries, \'t_counter\' and \'window\', to keep track of character counts in \'t\' and the current window, respectively.\n\n3. We populate \'t_counter\' by iterating through the characters of \'t\' and incrementing their counts. It helps us keep track of the characters we need to match in \'s\'.\n\n4. We define \'have\' to track how many required characters we have in our current window and \'need\' to represent the total number of characters required. We also initialize \'ans\' and \'ans_size\' to store the minimum window and its size. \'ans\' starts as [-1, -1] to represent an invalid window, and \'ans_size\' starts as positive infinity.\n\n5. We set \'left\' to 0 as the start of our sliding window.\n\n6. We iterate through \'s\' using a \'right\' pointer to expand the window:\n   - Update \'window\' to keep track of character counts in the current window.\n   - If the character at \'right\' is in \'t_counter\' and its count in \'window\' matches its count in \'t_counter\', we increment \'have\'.\n\n7. We enter a while loop as long as we have all required characters in our window:\n   - If the current window size is smaller than \'ans_size\', we update \'ans\' and \'ans_size\' to record this as a potential minimum window.\n   - We decrement the count of the character at \'left\' in \'window\'.\n   - If the character at \'left\' is in \'t_counter\' and its count in \'window\' is less than its count in \'t_counter\', we decrement \'have\'.\n   - We move \'left\' to the right to shrink the window.\n\n8. After the loop, we have found the minimum window. We return the substring of \'s\' from \'ans[0]\' to \'ans[1]\' if \'ans_size\' is not still equal to positive infinity. Otherwise, we return an empty string.\n\n# Complexity\n- Time complexity: O(s + t), where \'s\' is the length of string \'s\' and \'t\' is the length of string \'t\'.\n- Space complexity: O(s + t) due to the dictionaries \'t_counter\' and \'window\'.\n\n\n# Code\n```\nclass Solution {\npublic:\n    string minWindow(string s, string t) {\n        if(t == ""){\n            return "";\n        }\n\n        unordered_map<char , int> t_counter , window ;\n\n        for(auto x : t){\n            t_counter[x] = 1 + t_counter[x];\n        }\n\n        int have = 0 , need = t_counter.size() , ans_size = INT_MAX;\n        vector<int> ans;\n        int left = 0 ;\n\n        for(int right = 0 ; right < s.size() ; right++){\n            window[s[right]] = 1 + window[s[right]] ;\n\n            if(t_counter.find(s[right]) != t_counter.end() && window[s[right]] == t_counter[s[right]]){\n                have++;\n            }\n\n            while(have == need){\n                if((right - left + 1) < ans_size){\n                    ans = {left , right} ;\n                    ans_size = right - left + 1 ;\n                }\n                \n                window[s[left]] -= 1 ;\n                if(t_counter.find(s[left]) != t_counter.end() && window[s[left]] < t_counter[s[left]]){\n                    have--;\n                }\n                left++ ;\n            }  \n        }\n\n        return ans_size != INT_MAX ? s.substr(ans[0] , ans[1]-ans[0]+1) : "" ;\n        \n        \n    }\n};\n```\n\n# Please upvote the solution if you understood it.\n![1_3vhNKl1AW3wdbkTshO9ryQ.jpg](https://assets.leetcode.com/users/images/dadbbd36-fa57-446a-97f0-c2b319a77959_1698428627.70189.jpeg)\n
['Sliding Window', 'C++']