[]Topic
Sliding Window Problems
Sliding-window problems — find the longest, shortest, or best contiguous subrange that satisfies a constraint.
Easy · 1
Medium · 2
Hard · 1
Sliding window is the single most useful pattern for interview-style string problems. Whenever the question asks for the longest, shortest, or best contiguous subrange that satisfies a constraint, sliding window collapses what looks like an O(n²) scan into an O(n) two-pointer sweep that maintains a running summary of the current window.
The pattern has two flavors. A fixed-size window slides one element at a time across the array — used for "max sum of k consecutive elements" and rolling averages. A variable-size window grows when the constraint allows and shrinks when it's violated — used for "longest substring without repeating characters", "longest repeating character replacement", and "minimum window substring". Both flavors lean on a fast incremental update — usually a hash map or a counter — so the per-step work stays O(1).
The Ratta sliding-window track covers the canonical interview set: Best Time to Buy and Sell Stock, Longest Substring Without Repeating Characters, Longest Repeating Character Replacement, and Minimum Window Substring. Every problem walks through the loop invariant — what's true at the boundaries — so the technique becomes muscle memory, not a memorized template.