Sliding Window

Noun · Development

Definitions

  1. An algorithmic technique that maintains a window (subarray/substring) that slides through data, expanding or contracting to find optimal solutions. Fixed-size windows track aggregates like rolling averages. Variable-size windows find the longest/shortest subarray satisfying a condition. Reduces O(n²) brute force to O(n).

    In plain English: A technique for efficiently processing chunks of an array by sliding a window across it instead of recalculating from scratch.

    Example: "Find the maximum sum of any 5 consecutive elements — the sliding window adds the new element and removes the oldest in O(1) per step."

Related Terms