Beats 100% 🚀➡️Detailed Explanation 💯➡️[Java/C++/Python3/JavaScript]
Intuition\n1. Window Creation with Two Pointers:\n    - Use two pointers, one for the left end of the window and another for the right end, to create a window o
# Intuition\n1. **Window Creation with Two Pointers:**\n    - Use two pointers, one for the left end of the window and another for the right end, to create a window of letters in string `s`.\n    - This window should aim to contain all the characters present in string `t`.\n2. **Expanding the Window:**\n    - Start by expanding the right pointer until all the characters from string t are included in the window.\n3. **Shrinking the Window:**\n    - Once all characters from t are covered, start moving the left pointer to minimize the size of the window while still ensuring all characters from t are present.\n    - This ensures the smallest possible window containing all characters from t is achieved.\n4. **Continued Adjustment of Pointers:**\n    - Continue the process of expanding the right pointer and shrinking the left pointer until reaching the end of string `s`.\n    - This ensures thorough coverage and minimizes the size of the window containing all characters from `t`.\n\n# Approach\n1. **Initialization:**\n    - Initialize an empty string `ans` to store the minimum window substring.\n    - Initialize two HashMaps: `mapT` to store the frequency of characters in string `t`, and `mapS` to store the frequency of characters in the current window of string `s`.\n    - Initialize `mct` to track the number of characters matched so far and `dmct` to represent the desired match count, which is the length of string `t`.\n2. **Iterating through the string:**\n    - Use two pointers, `i` and `j`, to represent the window boundaries. Start both pointers at `-1`.\n    - `i` will be moved forward to expand the window, and `j` will be moved forward to shrink the window.\n3. **Expanding the window (while loop):**\n    - Increment `i` until either the end of string `s` is reached or all characters from string `t` are found (`mct` reaches `dmct`).\n    - Update mapS with the frequency of characters encountered. If a character is found which is present in t, increment mct.\n4. **Shrinking the window (`nested while loop`):**\n    - After expanding the window, increment `j` until the minimum window containing all characters from `t` is found (`mct` equals `dmct`).\n    - Update the ans if the current window is smaller than the previous minimum.\n    - Update `mapS` accordingly and decrement `mct` if a character is no longer in the window.\n5. **Check for completion:**\n    - Break the loop if neither `flag1` (expanding) nor `flag2` (shrinking) flags are set. This indicates that both pointer movements did not happen, implying that the windows cannot be expanded or shrunk further.\n6. **Return the minimum window substring found:**\n    - Return the `ans` after the while loop exits, which contains the minimum window substring.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n)$$   *n is length of string s*\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$   *n is length of string s*\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```Java []\nclass Solution {\n    public String minWindow(String s, String t) {\n        if(s.equals(t)){\n            return s;\n        }  \n        String ans = "";\n        HashMap<Character, Integer> mapT = new HashMap<>(); //frequecny of t\n        for(char ch : t.toCharArray()) {\n            mapT.put(ch, mapT.getOrDefault(ch,0)+1);\n        }\n\n        int mct = 0; //match count\n        int dmct = t.length(); //desired match count\n        HashMap<Character, Integer> mapS = new HashMap<>();\n        int i = -1;\n        int j = -1;\n\n        while(true) {\n            boolean flag1 = false;\n            boolean flag2 = false;\n\n            //acquire the character\n            while(i < s.length()-1 && mct < dmct) {\n                i++;\n                char ch = s.charAt(i);\n                mapS.put(ch, mapS.getOrDefault(ch, 0)+1);\n\n                if(mapS.getOrDefault(ch, 0) <= mapT.getOrDefault(ch,0)){\n                    mct++;\n                }\n                flag1=true;\n            }\n\n            // Collect answers and release\n            while(j < i && mct == dmct) {\n                j++;\n                String pans = s.substring(j, i+1); //pans = potential answer\n                if(ans.length()==0 || pans.length() < ans.length()) {\n                    ans = pans;\n                }\n\n                char ch = s.charAt(j);\n                if(mapS.get(ch)==1) {\n                    mapS.remove(ch);\n                }\n                else {\n                    mapS.put(ch, mapS.get(ch)-1);\n                }\n\n                if(mapS.getOrDefault(ch, 0) < mapT.getOrDefault(ch, 0)) {\n                    mct--;\n                }\n                flag2=true;\n            }\n            if(f1==false && f2==false) {\n                break;\n            } \n        }\n        return ans;\n    }\n}\n```\n```C++ []\nclass Solution {\npublic:\n    string minWindow(string s, string t) {\n        if(s == t) {\n            return s;\n        }  \n        string ans = "";\n        unordered_map<char, int> mapT; // frequency of t\n        for(char ch : t) {\n            mapT[ch]++;\n        }\n\n        int mct = 0; // match count\n        int dmct = t.length(); // desired match count\n        unordered_map<char, int> mapS;\n        int i = -1;\n        int j = -1;\n\n        while(true) {\n            bool f1 = false;\n            bool f2 = false;\n\n            // Acquire the character\n            while(i < s.length()-1 && mct < dmct) {\n                i++;\n                char ch = s[i];\n                mapS[ch]++;\n\n                if(mapS[ch] <= mapT[ch]) {\n                    mct++;\n                }\n                f1 = true;\n            }\n\n            // Collect answers and release\n            while(j < i && mct == dmct) {\n                j++;\n                string pans = s.substr(j, i-j+1); // pans = potential answer\n                if(ans.length() == 0 || pans.length() < ans.length()) {\n                    ans = pans;\n                }\n\n                char ch = s[j];\n                if(mapS[ch] == 1) {\n                    mapS.erase(ch);\n                } else {\n                    mapS[ch]--;\n                }\n\n                if(mapS[ch] < mapT[ch]) {\n                    mct--;\n                }\n                f2 = true;\n            }\n            if(!f1 && !f2) {\n                break;\n            } \n        }\n        return ans;\n    }\n};\n```\n```Python3 []\nclass Solution:\n    def minWindow(self, s: str, t: str) -> str:\n        if s == t:\n            return s\n        ans = ""\n        mapT = {}  # frequency of t\n        for ch in t:\n            mapT[ch] = mapT.get(ch, 0) + 1\n\n        mct = 0  # match count\n        dmct = len(t)  # desired match count\n        mapS = {}\n        i = -1\n        j = -1\n\n        while True:\n            f1 = False\n            f2 = False\n\n            # Acquire the character\n            while i < len(s) - 1 and mct < dmct:\n                i += 1\n                ch = s[i]\n                mapS[ch] = mapS.get(ch, 0) + 1\n\n                if mapS.get(ch, 0) <= mapT.get(ch, 0):\n                    mct += 1\n                f1 = True\n\n            # Collect answers and release\n            while j < i and mct == dmct:\n                j += 1\n                pans = s[j:i + 1]  # pans = potential answer\n                if not ans or len(pans) < len(ans):\n                    ans = pans\n\n                ch = s[j]\n                if mapS[ch] == 1:\n                    del mapS[ch]\n                else:\n                    mapS[ch] -= 1\n\n                if mapS.get(ch, 0) < mapT.get(ch, 0):\n                    mct -= 1\n                f2 = True\n\n            if not f1 and not f2:\n                break\n        return ans\n```\n```JavaScript []\n/**\n * @param {string} s\n * @param {string} t\n * @return {string}\n */\nvar minWindow = function(s, t) {\n    if (s === t) {\n        return s;\n    }  \n    let ans = "";\n    const mapT = new Map(); // frequency of t\n    for (const ch of t) {\n        mapT.set(ch, (mapT.get(ch) || 0) + 1);\n    }\n\n    let mct = 0; // match count\n    const dmct = t.length; // desired match count\n    const mapS = new Map();\n    let i = -1;\n    let j = -1;\n\n    while (true) {\n        let f1 = false;\n        let f2 = false;\n\n        // Acquire the character\n        while (i < s.length - 1 && mct < dmct) {\n            i++;\n            const ch = s[i];\n            mapS.set(ch, (mapS.get(ch) || 0) + 1);\n\n            if (mapS.get(ch) <= mapT.get(ch) || 0) {\n                mct++;\n            }\n            f1 = true;\n        }\n\n        // Collect answers and release\n        while (j < i && mct === dmct) {\n            j++;\n            const pans = s.substring(j, i + 1); // pans = potential answer\n            if (ans.length === 0 || pans.length < ans.length) {\n                ans = pans;\n            }\n\n            const ch = s[j];\n            if (mapS.get(ch) === 1) {\n                mapS.delete(ch);\n            } else {\n                mapS.set(ch, mapS.get(ch) - 1);\n            }\n\n            if ((mapS.get(ch) || 0) < (mapT.get(ch) || 0)) {\n                mct--;\n            }\n            f2 = true;\n        }\n        if (!f1 && !f2) {\n            break;\n        } \n    }\n    return ans;\n};\n```
['Sliding Window', 'C++', 'Java', 'Python3', 'JavaScript']