O(N) JAVA Sliding Window solution with explanation
Sliding Window Solution:\n\n    1) Spread the right pointer until it satisfies the requirement  \n    2) Shrink the left pointer to get the minimum range \n    
**Sliding Window Solution:**\n\n    1) Spread the right pointer until it satisfies the requirement  \n    2) Shrink the left pointer to get the minimum range \n    3) Keep the above steps.\n\n**Time complexity = O(2n) = O(n)**\n\nThere're 2 loops: for loop of i, while loop of j. As j only steps forward, never steps backward. So time complexity = O(n) + O(n) = O(2n) = O(n)\n\n**JAVA Code:**  \n \nA little trick is using two arrays to count the characters in s and t, instead of HashMap, to avoid TLE.\n\n    boolean sContainsT(int mapS[], int mapT[]) {// Runtime = O(256) = O(1)\n        for (int i = 0; i < mapT.length; i++) {// s should cover all characters in t\n            if (mapT[i] > mapS[i])\n                return false; \n        }           \n        return true;\n    }\n    \n    public String minWindow(String s, String t) {   \n        int mapS[] = new int[256];// Count characters in s\n        int mapT[] = new int[256];// Count characters in t      \n        for (char ch : t.toCharArray())\n            mapT[ch]++;\n    \n        String res = "";\n        int right = 0, min = Integer.MAX_VALUE;         \n        for (int i = 0; i < s.length(); i++) {// Two pointers of the sliding window: i(left), right\n            while (right < s.length() && !sContainsT(mapS, mapT)) {// Extend the right pointer of the sliding window\n                mapS[s.charAt(right)]++;\n                right++;\n            }\n            if (sContainsT(mapS, mapT) && min > right - i + 1) {\n                res = s.substring(i, right);\n                min = right - i + 1;\n            }\n            mapS[s.charAt(i)]--;// Shrink the left pointer from i to i + 1\n        }\n        return res;\n    }
[]