Python two pointer sliding window with explanation
The idea is we use a variable-length sliding window which is gradually applied across the string. We use two pointers: start and end to mark the sliding window.
The idea is we use a variable-length sliding window which is gradually applied across the string. We use two pointers: start and end to mark the sliding window.  We start by fixing the start pointer and moving the end pointer to the right. The way we determine the current window is a valid one is by checking if all the target letters have been found in the current window. If we are in a valid sliding window, we first make note of the  sliding window of the most minimum length we have seen so far. Next we try to contract the sliding window by moving the start pointer. If the sliding window continues to be valid, we note the new minimum sliding window. If it becomes invalid (all letters of the target have been bypassed), we break out of the inner loop and go back to moving the end pointer to the right.\n\n```python\nclass Solution(object):\n    def minWindow(self, search_string, target):\n        """\n        :type s: str\n        :type t: str\n        :rtype: str\n        """\n        target_letter_counts = collections.Counter(target)\n        start = 0\n        end = 0\n        min_window = ""\n        target_len = len(target)        \n        \n        for end in range(len(search_string)):\n\t\t\t# If we see a target letter, decrease the total target letter count\n\t\t\tif target_letter_counts[search_string[end]] > 0:\n                target_len -= 1\n\n            # Decrease the letter count for the current letter\n\t\t\t# If the letter is not a target letter, the count just becomes -ve\n\t\t\ttarget_letter_counts[search_string[end]] -= 1\n            \n\t\t\t# If all letters in the target are found:\n            while target_len == 0:\n                window_len = end - start + 1\n                if not min_window or window_len < len(min_window):\n\t\t\t\t\t# Note the new minimum window\n                    min_window = search_string[start : end + 1]\n                    \n\t\t\t\t# Increase the letter count of the current letter\n                target_letter_counts[search_string[start]] += 1\n                \n\t\t\t\t# If all target letters have been seen and now, a target letter is seen with count > 0\n\t\t\t\t# Increase the target length to be found. This will break out of the loop\n                if target_letter_counts[search_string[start]] > 0:\n                    target_len += 1\n                    \n                start+=1\n                \n        return min_window\n```
[]