Skip to content
C Codeloom

Topics / Sliding Window

🪟

Sliding Window

A moving window over a sequence — fixed and variable size, with O(n) substring and subarray solutions.

Why learn Sliding Window?

  • Solves nearly every "longest / shortest substring with property X" problem.

  • Pairs perfectly with hash maps and deques.

  • Once internalized, you spot it in three problems out of five.

What you can build with Sliding Window

Longest substring with K distinct characters Fixed-size subarray problems Minimum-window / minimum-cover problems

Sliding Window tutorials

3 articles

Hand-written tutorials, ordered as a recommended learning path.

  1. 01 Sliding Window A practical guide to sliding window — fixed-size vs variable-size windows, expand/shrink invariants, and six classic problems with worked Python solutions.
  2. 02 Longest Substring Solve LeetCode 3 Longest Substring Without Repeating Characters using a sliding window with a hash map. We go from brute force to a clean O(n) sweep.
  3. 03 Sliding Window Max Solve LeetCode 239 Sliding Window Maximum in O(n) using a monotonic deque. Step-by-step walkthrough, interview script, and complexity analysis.