What is Sliding Window

Pattern overview

sliding window (variable-size subarray technique) maintains a dynamic range over sequential data, expanding or contracting based on conditions. You use it when finding optimal subarrays or substrings that satisfy constraints. It reduces O(n2)O(n^2) substring enumeration to O(n)O(n) by reusing computation from the previous window position.

You'll see this in substring problems, subarray sums, and sequence optimization. If you can explain these concepts in your own words, you'll solve related problems faster under interview pressure.

1770079118418-mq3w1p0vvz.jpg