MediumVery High Frequency35 min
Sliding Window
Handle subarray/substring problems efficiently using a dynamic window over the input.
Maintain a dynamic window over a sequence to find subarrays/substrings satisfying a condition in O(n) instead of O(n²) or O(n┬│).
The Sliding Window Technique
Operations — Step by Step
Fixed Window (k=3)
O(n)Slide right: add new element, subtract removed elementStep-by-step1 / 4
Initial window [2,1,5], sum=8
Build the first window of size k=3. Sum = 2+1+5 = 8. This is the initial max.