Data Structures19 sections · 729 units
Open in Course

Lessons from Sliding Window

Recognizing the pattern

What did you learn?

1.1. Sliding window works for contiguous subarray/substring problems where you need to find an optimal window satisfying some constraint.

2.2. Fixed windows slide one position at a time. Variable windows expand and shrink based on conditions.

3.3. Each element is processed at most twice (once added, once removed). You get O(n)O(n) time despite nested loops. Look for keywords: "contiguous," "subarray," "substring," "window of size k."