WorkspaceLearning path
Level 1 · Foundations
BUILD YOUR INTUITION

Sliding Window

Maintain a contiguous range, reusing information as its boundaries move.

THE MENTAL MODEL

When should this come to mind?

Maintain a contiguous range, reusing information as its boundaries move.

Longest or shortest substringContiguous subarrayFixed-size KFrequency constraints

What makes it work

Both boundaries should advance monotonically; updates must be cheaper than rebuilding the window.

When to choose something else

A shrinking rule must be valid. For example, sum-based windows with negative numbers may not be monotonic.

See the pattern in action

Change the input. Follow the state. Make it yours.