JS optimized solution with explanations O(t+s) time O(t+s) space
Note\n- Should be pretty straight forward if you did these problems before: 567-permutation-in-string, 438. Find All Anagrams in a String\n- Do those first.\n- 
# Note\n- Should be pretty straight forward if you did these problems before: [567-permutation-in-string](https://leetcode.com/problems/permutation-in-string/), [438. Find All Anagrams in a String](https://leetcode.com/problems/find-all-anagrams-in-a-string/)\n- Do those first.\n- Here is the idea:\n1. create a hashmap that counts character frequency of t\n2. use two pointers to define your window size\n3. whenever you encounter a character in s that is in your hashmap, decrease the count. When the count is 0, it means that you used up the required amount of this character. Therefore you increase your "match" count.\n4. When match is equal to numbers of keys in your hashmap, it means that you have a solution. Notice that "uniqueChars" is the number of keys in the hashmap.\n5. when you have a solution, try to decrease your window size by increasing the left pointer until the window is no longer a solution.\n6. record the solution you had before\n\n# Big O Analysis\n- Time: O(t) time to build the hashmap. O(s+s) for  window sliding since in the worst case the right and left pointer loop through the entire string s once. Therefore overall time complexity is O(t + s)\n- Space: O(t) for the hashmap in the worst case. O(s) for the answer in the worst case if s is a permutation of t. Therefore overall space complexity is O(t+s)\n\n```javascript\n/**\n * @param {string} s\n * @param {string} t\n * @return {string}\n */\nvar minWindow = function(s, t) {\n  // count t\'s frequency of its characters\n  let map = {}, uniqueChars = 0;\n  for (let char of t) {\n    if (char in map) {\n      map[char] += 1;\n    } else {\n      map[char] = 1;\n      uniqueChars += 1;\n    }\n  }\n  \n  let ans = \'\';\n  let left = 0, match = 0;\n  for (let right = 0; right < s.length; right++) {\n    let rightChar = s[right];\n    if (rightChar in map) {\n      map[rightChar] -= 1;\n      if (map[rightChar] === 0) match += 1;\n    }\n    \n    if (match === uniqueChars) { // there is a solution\n      // try to shrink the window from the left\n      while (match === uniqueChars) {\n        let leftChar = s[left++];\n        if (map[leftChar] === 0) match -= 1;\n        map[leftChar] += 1;\n      }\n      \n      // record the solution, notice that you need to use left-1 instead of left when slicing\n      let solution = s.slice(left-1, right+1);\n      ans = (ans === \'\')? solution: (ans.length > solution.length)? solution: ans;\n    }\n  }\n  return ans;\n}\n```
['Two Pointers', 'Sliding Window', 'JavaScript']