DSA sheet · Sliding Window
Sliding Window DSA Notebook
My study notes from the Sliding Window playlist. Each page is written so that a beginner (or me, after forgetting everything) can read it once and understand when the window grows, when and why it shrinks, the Python code line by line, and a full dry run with the window drawn moving across the array.
[left..right] and reuse its work: add the new item on the right, and remove items from the left only when the window breaks the rule.Each item enters once and leaves once, so the whole scan is O(n). Two shapes: fixed size k (slide by one each step) and variable size (grow until invalid, then shrink).
Every page follows the same order:
① question in simple words → ② constraints → ③ intuition → ④ building the logic from examples → ⑤ approach steps → ⑥ code → ⑦ line by line → ⑧ dry run with the window drawn → ⑨ complexity & remember
Start here
Fixed-size window
- 2Maximum Subarray with Sum Kbrute → window
- 9Sliding Window Maximummonotonic deque
- 10Find All Anagrams in a Stringvideos 10 & 11
- 13Permutation in Stringfrequency map
Variable window: longest valid
- 3Max Consecutive Onesbrute → one pass
- 4Max Consecutive Ones IIIat most k zeros
- 7Fruits Into Basketsat most 2 types
- 11Longest Substring Without Repeatingset / last index
- 12Longest Substring with K Uniqueexactly k
Variable window: shortest valid
Counting windows
- 5Subarray Product Less Than Kcount += r − l + 1
- 8Subarrays with K Different IntegersatMost(k) − atMost(k−1)
Kadane's Algorithm
- 15Maximum Subarray (Kadane's Algorithm)extend or restart
- 16Maximum Product Subarraymax & min · prefix/suffix
Numbers follow the playlist order (videos 10 and 11 share page 10, so the pages are numbered 1–14; pages 15–16 are the Kadane videos, playlist #22–23). "Next →" at the top of each page follows that order.