Member-only story
Pattern Recognition For Algorithms Part 3: Sliding Window
Two pointers never has to undo anything it already decided. A pointer moves forward, whatever got decided at that position stands, and the pointer never revisits it. Sliding window breaks that rule on purpose, its entire identity as a pattern separate from two pointers comes from the one thing two pointers can’t do, take something back.
Part 3 of the book, sliding window, is published now. Four shapes this time, a window of a size handed over directly, a window that grows toward a maximum, a window that shrinks toward a minimum, and windows that never announce themselves as windows in the problem statement at all. Eleven worked problems sit behind those four.
So what actually makes something a sliding window instead of just two pointers moving through the same array?
What A Sliding Window Actually Is
A sliding window is a contiguous range of an array or string, tracked by two indices, left and right, that moves forward one step at a time while a running value summarizes whatever currently sits inside it.
Take [2, 1, 5, 1, 3, 2], every group of three elements next to each other. The first window covers indices 0 to 2, [2, 1, 5], sum 8. Slide forward one step, 2 leaves from the left, 1 enters from the right, [1, 5, 1], sum 7…










