Index Ai Academy
Glossary · Phase 7 · Software engineering

Sliding window

Also written: sliding windows

A range that moves along the data, adding what enters and removing what leaves instead of starting over.

A sliding window is a range that moves along the data. For a fixed size, like "the busiest 7 days", don't re-add all 7 days at each step: add the day that enters and subtract the day that leaves. For a variable size, grow the window on the right and shrink it from the left whenever it breaks a rule. The longest stretch of trail markers without a repeated color, for example, keeps a set of what's inside the window.

Try it now

Most problems give themselves away: sorted input, a count, a range, or a fixed-size window.

Learn it properly

Patterns for coding problems · Two pointers, counting with dictionaries, prefix sums and sliding windows: O(n) answers to classic problems. About 45 minutes.

Create a free account See what's in the lesson

Other terms from the same lesson

Never trained an AI?

Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account.

Teach it to write