C++/JAVA/Python  | 🚀 ✅ Sliding Window | ✅ Fully Explained | ✅ Hash Table | ✅ String
Intuition:\nThe problem asks to find the minimum window in s that contains all the characters of t. One way to approach this problem is to use a sliding window 
# Intuition:\nThe problem asks to find the minimum window in s that contains all the characters of t. One way to approach this problem is to use a sliding window technique. We can maintain a window that starts from the beginning of s and moves forward until it contains all the characters of t. Once we have such a window, we can try to shrink it by moving the window\'s start pointer forward while still keeping all the characters of t in the window. This will give us the minimum window.\n\n#Approach:\n\n1. Check if s is shorter than t. If it is, there is no possible solution, and we return an empty string.\n2. Create a frequency map of characters in t.\n3. Initialize count, start, min_length, and min_start to 0.\n4. Traverse the string s using the end pointer.\n5. If the current character in s is present in the frequency map, increment the count.\n6. Decrement the frequency of the current character in the frequency map.\n7. If the count equals the length of t, it means we have found a window that contains all characters of t. Now we try to shrink the window by moving the start pointer forward until the window still contains all the characters of t.\n8. If the length of the current window is smaller than the minimum length so far, update the minimum length and the minimum start.\n9. Increment the frequency of the character at the start pointer and decrement the count.\n10. Return the minimum window or an empty string if no window exists.\n# Complexity:\n- Time complexity: O(N), where N is the length of the string s. We traverse the string s once.\n- Space complexity: O(M), where M is the length of the string t. We create a frequency map of characters in t.\n\n# Code\n```\nclass Solution {\npublic:\n    string minWindow(string s, string t) {\n        if(s.size() < t.size()){\n            return "";\n        }\n        unordered_map<char,int> map;\n        for(int i=0;i<t.size();i++){\n            map[t[i]]++;\n        }\n        int count=0,start=0,min_length = INT_MAX, min_start = 0;\n        for(int end=0; end<s.size(); end++){\n            if(map[s[end]]>0){\n                count++;\n            }\n            map[s[end]]--; \n            if(count == t.length()) { \n                while(start < end && map[s[start]] < 0){\n                    map[s[start]]++, start++;\n                } \n                if(min_length > end-start){\n                    min_length = end-(min_start=start)+1; \n                }\n                map[s[start++]]++; \n                count--;\n            }\n        }\n        return min_length == INT_MAX ? "" : s.substr(min_start, min_length);\n    }\n};\n```\n# JAVA\n```\nclass Solution {\n    public String minWindow(String s, String t) {\n        if(s.length() < t.length()){\n            return "";\n        }\n        Map<Character,Integer> map = new HashMap<>();\n        for(int i=0;i<t.length();i++){\n            map.put(t.charAt(i), map.getOrDefault(t.charAt(i), 0) + 1);\n        }\n        int count=0,start=0,min_length = Integer.MAX_VALUE, min_start = 0;\n        for(int end=0; end<s.length(); end++){\n            if(map.containsKey(s.charAt(end))){\n                if(map.get(s.charAt(end))>0){\n                    count++;\n                }\n                map.put(s.charAt(end), map.get(s.charAt(end))-1); \n            }\n            if(count == t.length()) { \n                while(start < end && (!map.containsKey(s.charAt(start)) || map.get(s.charAt(start)) < 0)){\n                    if(map.containsKey(s.charAt(start))){\n                        map.put(s.charAt(start), map.get(s.charAt(start))+1);\n                    }\n                    start++;\n                } \n                if(min_length > end-start+1){\n                    min_length = end-(min_start=start)+1; \n                }\n                if(map.containsKey(s.charAt(start))){\n                    map.put(s.charAt(start), map.get(s.charAt(start))+1);\n                }\n                count--;\n                start++;\n            }\n        }\n        return min_length == Integer.MAX_VALUE ? "" : s.substring(min_start, min_start+min_length);\n    }\n}\n\n```\n# Python\n```\nclass Solution(object):\n    def minWindow(self, s, t):\n        if len(s) < len(t):\n            return ""\n        map = {}\n        for char in t:\n            if char in map:\n                map[char] += 1\n            else:\n                map[char] = 1\n        count = 0\n        start = 0\n        min_length = float("inf")\n        min_start = 0\n        for end in range(len(s)):\n            if s[end] in map:\n                map[s[end]] -= 1\n                if map[s[end]] >= 0:\n                    count += 1\n            while count == len(t):\n                if min_length > end - start + 1:\n                    min_length = end - start + 1\n                    min_start = start\n                if s[start] in map:\n                    map[s[start]] += 1\n                    if map[s[start]] > 0:\n                        count -= 1\n                start += 1\n        return "" if min_length == float("inf") else s[min_start:min_start+min_length]\n\n```
['Hash Table', 'Sliding Window', 'Python', 'C++', 'Java']