Pattern
Sliding Window
Use a window when the answer is a run of neighbouring items that must keep some property. Grow the window on the right and shrink it from the left when the property breaks. The usual cost is O(n) time, because each item enters and leaves once.
1. Best Time to Buy and Sell Stockarray · sliding window · greedyEasy2. Longest Substring Without Repeating Charactersstring · sliding window · hash mapMed.3. Longest Repeating Character Replacementstring · sliding window · hash mapMed.4. Permutation in Stringstring · sliding window · hash mapMed.5. Minimum Window Substringstring · sliding window · hash mapHard6. Sliding Window Maximumarray · sliding window · deque · monotonic queueHard