Sliding Window
This is a premium interview-preparation course built around one insight: when a problem asks about the best contiguous subarray or substring, you rarely need to re-examine a range from scratch. A **sliding window** carries just enough state — a running sum, a frequency map, a monotonic deque — and updates it in O(1) as the window moves, collapsing an O(n^2) brute force into O(n). You will start with the mental model (fixed vs variable windows, when to expand and when to shrink, and the two-pointer relationship), then work through curated problems grouped by the patterns interviewers actually test: fixed windows, variable windows, frequency-driven windows, the exactly-K trick, and premium deque and prefix-hybrid problems. Every lesson identifies the pattern first, visualises the window, then shows a clean Java 17 implementation.
24
Curated lessons
6
Learning modules
6h 34m
Est. study time
10
Target companies
What you'll learn
- Recognise the sliding-window signal: contiguous subarray/substring plus a monotone feasibility condition.
- Choose the right window shape — fixed size, or variable with an expand/shrink invariant.
- Maintain window state in O(1): running aggregates, frequency maps, and monotonic deques.
- Apply the atMost(K) - atMost(K-1) trick to count windows with an exact property.
Your progress
0 / 24
problems completed
24 available now · keep going!
Mark lessons complete as you work through them. Progress is saved on this device and syncs to your account when you sign in.
Learning roadmap
Work top to bottom — each module builds on the last.
- 1
Sliding Window Fundamentals
Carry window state; slide instead of rebuildThe mental model: fixed vs variable windows, when to expand and when to shrink, and the two-pointer invariant that keeps a window valid.
7/7 problems54m - 2
Fixed Window
Constant-size window: add right, remove left-kA window of constant size k: add the entering element, drop the leaving one, and read the answer at every step.
3/3 problems40m - 3
Variable Window
Expand right; shrink left while invariant is violatedGrow the window while it stays valid, then shrink from the left the moment it breaks — the expand/shrink template.
4/4 problems1h 19m - 4
Frequency Based Windows
Window + frequency map / match counterTrack character or number counts inside the window to match anagrams, permutations, and bounded-distinct constraints.
3/3 problems56m - 5
Advanced Sliding Window
exactly(K) = atMost(K) - atMost(K-1)Count windows with an exact property using the atMost(K) minus atMost(K-1) trick, and map binary/parity conditions onto it.
4/4 problems1h 30m - 6
Premium Problems
Monotonic deque / complement reframingWindows that need a monotonic deque to answer max/min in O(1), or a prefix-sum reframing to become a window at all.
3/3 problems1h 15m
Modules
6 themed modules from fundamentals to advanced.
Sliding Window Fundamentals
The mental model: fixed vs variable windows, when to expand and when to shrink, and the two-pointer invariant that keeps a window valid.
Fixed Window
A window of constant size k: add the entering element, drop the leaving one, and read the answer at every step.
Variable Window
Grow the window while it stays valid, then shrink from the left the moment it breaks — the expand/shrink template.
Frequency Based Windows
Track character or number counts inside the window to match anagrams, permutations, and bounded-distinct constraints.
Advanced Sliding Window
Count windows with an exact property using the atMost(K) minus atMost(K-1) trick, and map binary/parity conditions onto it.
Premium Problems
Windows that need a monotonic deque to answer max/min in O(1), or a prefix-sum reframing to become a window at all.
Full curriculum
17 problems and 7 concept lessons in learning order.
- 1Fixed WindowSliding Window Fundamentals Concept
- 2Variable WindowSliding Window Fundamentals Concept
- 3Expanding the WindowSliding Window Fundamentals Concept
- 4Shrinking the WindowSliding Window Fundamentals Concept
- 5The Two-Pointer RelationshipSliding Window Fundamentals Concept
- 6Frequency Maps in WindowsSliding Window Fundamentals Concept
- 7Common Sliding Window PatternsSliding Window Fundamentals Concept
- 8Maximum Average Subarray IFixed WindowEasy
- 9Maximum Sum Subarray of Size KFixed WindowEasy
- 10Contains Duplicate IIFixed WindowEasy
- 11Longest Substring Without Repeating CharactersVariable WindowMedium
- 12Longest Repeating Character ReplacementVariable WindowMedium
- 13Minimum Size Subarray SumVariable WindowMedium
- 14Minimum Window SubstringVariable WindowHard
- 15Permutation in StringFrequency Based WindowsMedium
- 16Find All Anagrams in a StringFrequency Based WindowsMedium
- 17Fruit Into BasketsFrequency Based WindowsMedium
- 18Subarrays with K Different IntegersAdvanced Sliding WindowHard
- 19Binary Subarrays With SumAdvanced Sliding WindowMedium
- 20Count Number of Nice SubarraysAdvanced Sliding WindowMedium
- 21Max Consecutive Ones IIIAdvanced Sliding WindowMedium
- 22Sliding Window MaximumPremium ProblemsHard
- 23Longest Continuous Subarray with Absolute Diff Less Than or Equal to LimitPremium ProblemsMedium
- 24Minimum Operations to Reduce X to ZeroPremium ProblemsMedium