Week 18 of 43
Core DSA
WEEK 18 LEARNING MODULE
Sliding Window Technique
Processes contiguous subarrays and substrings in linear $O(n)$ time using Fixed-Size and Dynamic (Variable-Size) window expansion and contraction.
3 Practice Problems3 Core ConceptsVerified Curriculum: high Confidence
What You'll Learn
- ✓Master Sliding Window to avoid $O(n^2)$ or $O(n \cdot k)$ redundant subarray scans.
- ✓Implement Fixed-Size Sliding Windows: maintain running window state by adding the right element and removing the leftmost element.
- ✓Implement Variable-Size Sliding Windows: expand right pointer until an invariant is violated, then contract left pointer.
- ✓Track character and element frequencies using hash tables inside dynamic windows.
Core Concepts
Sliding Window Paradigm
O(n)Maintaining a continuous range [left, right] over an array or string that shifts or resizes dynamically.
Fixed-Size Window Invariant
O(n) time, O(1) spaceWindow size remains exactly k; updates take O(1) per step by subtracting arr[i-k] and adding arr[i].
Dynamic Window Expansion & Contraction
O(n) amortizedExpanding right pointer to include elements, contracting left pointer when constraints (e.g. distinct count > k) are exceeded.
Algorithms Covered
Maximum Average SubarrayLongest Substring Without Repeating CharactersFruit Into Baskets (K Distinct Elements)Max Consecutive Ones IIIMinimum Size Subarray Sum
Data Structures Applied
ArraysStringsHash MapsHash Sets
“Your big opportunity may be right where you are now. Open your eyes, and you'll find it in your windows.”
— Napoleon Hill