Sliding Window

  1. edge cases

  2. char note

  3. iterate string:

    • add char

    • window formed

    • move left side char, move window

    • until window do not satisfy, repeat

  4. two kinds of sliding window: 1) flexible length, usually max/min; 2) fixed length, usually find something.

flexible window

https://leetcode.com/problems/longest-substring-without-repeating-characters/description/arrow-up-right

https://leetcode.com/problems/minimum-window-substring/description/arrow-up-right

https://leetcode.com/problems/longest-substring-with-at-most-two-distinct-characters/description/arrow-up-right

https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters/description/arrow-up-right

https://leetcode.com/problems/minimum-window-substring/description/arrow-up-right

https://leetcode.com/problems/minimum-size-subarray-sumarrow-up-right

https://leetcode.com/problems/subarray-product-less-than-k/description/arrow-up-right

https://leetcode.com/problems/max-consecutive-ones-ii/discuss/96920/Java-clean-solution-easily-extensible-to-flipping-k-zero-and-follow-up-handledarrow-up-right

https://leetcode.com/problems/longest-repeating-character-replacement/description/arrow-up-right

fixed window

https://leetcode.com/problems/substring-with-concatenation-of-all-words/description/arrow-up-right

https://leetcode.com/problems/sliding-window-maximum/description/arrow-up-right https://leetcode.com/problems/sliding-window-median/description/arrow-up-right https://leetcode.com/problems/find-all-anagrams-in-a-string/description/arrow-up-right https://leetcode.com/problems/permutation-in-string/description/arrow-up-right

https://leetcode.com/problems/k-empty-slotsarrow-up-right https://leetcode.com/problems/can-place-flowers/description/arrow-up-right

Last updated