Sliding window keeps a moving range [l..r] and updates it in one pass. You expand `r` and move `l` to maintain a condition (e.g., sum <= X, at most K distinct). Many problems become O(n) instead of O(n^2) because each pointer moves forward at most n times.