0 day streak
2. Algorithms and patternsTwo pointers and sliding window

Two pointers and sliding window

Two pointers is a technique where you walk two positions through an array or string at the same time instead of trying every pair. In a sorted array you might start one at each end and move them inward based on what you see. A sliding window is the popular variant: both pointers move left to right, the right one extending the window to take in new items and the left one shrinking it whenever the window breaks a rule, such as having too many distinct characters. Since each pointer only moves forward, every item is added and removed at most once, turning a quadratic brute force into a single pass. It’s the go-to tool for “longest or shortest subarray that…” problems.

In this lesson: Step on a string. The window expands and shrinks with a live count map.