Simple Python two-pointer solution
Please see and vote for my solutions for these similar problems.\n1208. Get Equal Substrings Within Budget\n3. Longest Substring Without Repeating Characters\n1
Please see and vote for my solutions for these similar problems.\n[1208. Get Equal Substrings Within Budget](https://leetcode.com/problems/get-equal-substrings-within-budget/discuss/392901/Simple-Python-moving-window)\n[3. Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/discuss/348137/Simple-Python-two-pointer-solution-(52ms-beat-97.94))\n[159. Longest Substring with At Most Two Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters/discuss/348157/Simple-Python-two-pointer-solution)\n[340. Longest Substring with At Most K Distinct Characters](https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters/discuss/348216/Simple-Python-two-pointer-solution-(72-ms-beat-94.93))\n[992. Subarrays with K Different Integers](https://leetcode.com/problems/subarrays-with-k-different-integers/discuss/348984/Different-Python-two-pointer-solutions)\n[424. Longest Repeating Character Replacement](https://leetcode.com/problems/longest-repeating-character-replacement/discuss/363071/Simple-Python-two-pointer-solution)\n[209. Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum/discuss/344476/Simple-Python-two-pointer-solution)\n[713. Subarray Product Less Than K](https://leetcode.com/problems/subarray-product-less-than-k/discuss/344245/Simple-Python-solution-(beat-94.59))\n[76. Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/discuss/344533/Simple-Python-two-pointer-solution)\n\nSolution 1:\nKeep a moving window expand while curr_freqs < freqs , then shrink while curr_freqs >= freqs.\nEach time after shrinking, update the minimal window.\nWhere curr_freqs >= freqs means all([curr_freqs[c] >= freqs[c] for c in freqs]).\n```\n    def minWindow(self, s: str, t: str) -> str:\n        freqs = collections.Counter(t)\n        curr_freqs = {c: 0 for c in freqs}\n        res, res_len = "", float(\'inf\')\n        left = 0\n        for right in range(len(s)):\n            if s[right] in freqs:\n                curr_freqs[s[right]] += 1\n                while all([curr_freqs[c] >= freqs[c] for c in freqs]):\n                    if right - left + 1 < res_len:\n                        res_len = right - left + 1\n                        res = s[left:right+1]\n                    if s[left] in freqs:\n                        curr_freqs[s[left]] -= 1\n                    left += 1\n        return res\n```\n\nSolution 2: improve the efficiency of all([curr_freqs[c] >= freqs[c] for c in freqs])\n```\n    def minWindow(self, s: str, t: str) -> str:\n        need = collections.Counter(t)\n        missing = sum(need.values())\n        res, res_len = "", float(\'inf\')\n        left = 0\n        for right in range(len(s)):\n            if s[right] in need:\n                missing -= need[s[right]] > 0\n                need[s[right]] -= 1\n                while missing == 0:\n                    if right - left + 1 < res_len:\n                        res_len = right - left + 1\n                        res = s[left:right+1]\n                    if s[left] in need:\n                        missing += need[s[left]] >= 0\n                        need[s[left]] += 1\n                    left += 1\n        return res\n```
[]