Compile Ready
DSA
DSA/Sliding Window

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%

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. 1

    Sliding Window Fundamentals

    Carry window state; slide instead of rebuild

    The 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. 2

    Fixed Window

    Constant-size window: add right, remove left-k

    A window of constant size k: add the entering element, drop the leaving one, and read the answer at every step.

    3/3 problems40m
  3. 3

    Variable Window

    Expand right; shrink left while invariant is violated

    Grow the window while it stays valid, then shrink from the left the moment it breaks — the expand/shrink template.

    4/4 problems1h 19m
  4. 4

    Frequency Based Windows

    Window + frequency map / match counter

    Track character or number counts inside the window to match anagrams, permutations, and bounded-distinct constraints.

    3/3 problems56m
  5. 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. 6

    Premium Problems

    Monotonic deque / complement reframing

    Windows 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.

Full curriculum

17 problems and 7 concept lessons in learning order.

Techniques you'll master

Amortized AnalysisAnagram MatchingArrayArraysAt Most TrickBinary ArrayCountingData StructuresDequeDuplicate DetectionExpansionFixed SizeFixed WindowFrequency ArrayFrequency CountingFrequency MapHash MapHash SetInterview PatternsInvariantsJavaLeft PointerLongest WindowMonotonic QueueParityPrefix SumReframingRight PointerRunning SumShrinkingSliding WindowStringStringsTemplatesTwo PointersVariable SizeVariable Window