Category: sliding_window
-
LeetCode 424: Longest Repeating Character Replacement
link We can convert any characters to any other character. Say in a substring of s, the char has the most frequency. We should try matching other characters in the window to using replacements. In other words, as long as window_length – count_of[c] , the window is good. Longer windows can be good only if…
-
LeetCode 727: Minimum Window Subsequence
link Starting at each index of s1 we can try matching s2. Say len(s1) = and len(s2) = . Time: , space: . The window in s1 that contains s2 as a subsequence must have all characters of s2. So, to decrease the number of match_window() calls, we may first try finding the minimum window…
-
LeetCode 239: Sliding Window Maximum
link If we find that is bigger than all numbers in the current (sliding) window, we need to keep track of just from then on. With the above observation, we can maintain a queue of possible maxes for the current and future windows. The head of the queue will be the current max. Each number…