Sharing my straightforward O(n) solution with explanation
string minWindow(string S, string T) {\n        string result;\n        if(S.empty() || T.empty()){\n            return result;\n        }\n        unordered_ma
    string minWindow(string S, string T) {\n        string result;\n        if(S.empty() || T.empty()){\n            return result;\n        }\n        unordered_map<char, int> map;\n        unordered_map<char, int> window;\n        for(int i = 0; i < T.length(); i++){\n            map[T[i]]++;\n        }\n        int minLength = INT_MAX;\n        int letterCounter = 0;\n        for(int slow = 0, fast = 0; fast < S.length(); fast++){\n            char c = S[fast];\n            if(map.find(c) != map.end()){\n                window[c]++;\n                if(window[c] <= map[c]){\n                    letterCounter++;\n                }\n            }\n            if(letterCounter >= T.length()){\n                while(map.find(S[slow]) == map.end() || window[S[slow]] > map[S[slow]]){\n                    window[S[slow]]--;\n                    slow++;\n                }\n                if(fast - slow + 1 < minLength){\n                    minLength = fast - slow + 1;\n                    result = S.substr(slow, minLength);\n                }\n            }\n        }\n        return result;\n    }\n\nThere are three key variables in my solution: \n\n    unordered_map <char, int> map; unordered_map<char, int> window; int letterCounter;\n\nvariable "map" is used to indicate what characters and how many characters are in T.\n\nvariable "window" is to indicate what characters and how many characters are between pointer "slow" and pointer "fast".\n\nNow let's start.\n\nThe first For loop is used to construct variable "map".\n\nThe second For loop is used to find the minimum window.\n\nThe first thing we should do in the second For loop is to find a window which can cover T. I use "letterCounter" to be a monitor. If "letterCounter" is equal to T.length(), then we find this window. Before that, only the first If clause can be executed. However, after we find this window, the second If clause can also be executed. \n\nIn the second If clause, we move "slow" forward in order to shrink the window size. Every time finding a smaller window, I update the result. \n\nAt the end of program, I return result, which is the minimum window.
['Hash Table', 'Two Pointers', 'C++']