Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "".
The testcases will be generated such that the answer is unique.
Input: s = "ADOBECODEBANC", t = "ABC"
Output: "BANC"
Explanation: The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t.
Input: s = "a", t = "a"
Output: "a"
Explanation: The entire string s is the minimum window.
Input: s = "a", t = "aa"Output: ""Explanation: Both 'a's from t must be included in the window.Since the largest window of s only has one 'a', return empty string.
s and t consist of uppercase and lowercase English letters.Follow up: Could you find an algorithm that runs in O(m + n) time?
The most straightforward solution is to generate all possible substrings of s, and check if they contain all characters of t. However, this will be highly inefficient due to the large number of potential substrings, especially for long input strings.
s.t.t.The sliding window technique optimizes the process of finding the minimum window by maintaining two pointers to represent a window and expanding or shrinking it as needed.
right), and one to contract it (left).t, try to shrink it by moving the left pointer to minimize the window size.n is the length of s, and m is the length of t. This is because each character is processed at most twice (once when right traverses s, and once when left increments).m is the size of the tFreq HashMap that stores character frequencies of t, and k is the maximum number of unique characters in s.