Data Structures19 sections · 729 units
Open in Course

Vocabulary - Sliding Window

Moving subarray

A sliding window maintains a contiguous subarray that "slides" through the array. You track the window using two pointers: leftleft and rightright. There are two variants:

1.1. Fixed-size window: the window always has exactly kk elements. You slide it one position at a time.

2.2. Variable-size window: the window grows and shrinks based on some condition. Both achieve O(n)O(n) by processing each element at most twice: once when entering the window, once when leaving.