Skip to content

Sliding Window problems,
and the tell.

The answer is the best or longest contiguous run that satisfies a rule. 81 problems in the catalogue carry this tag, from first-week easy to interview hard.

Free to start. Running and submitting a solution never costs credits.

How the pattern actually works.

One mechanism, and the mistake that costs people the problem.

The tell. The answer is the best or longest contiguous run that satisfies a rule.

The mechanism. Grow the window to the right, and while it breaks the rule, shrink it from the left. The left edge never moves back, so every element enters and leaves once.

What goes wrong. Negative numbers. A window argument needs the total to move in one direction as the window grows, and negatives break that, which is where prefix sums take over.

The ones asked most often.

By how often the catalogue records them being set, not by our opinion.

  1. Longest Substring with At Most K Distinct CharactersMediumasked at 5 companies
  2. Count Zero Request ServersMediumasked at 5 companies
  3. Count Subarrays With Fixed BoundsHardasked at 4 companies
  4. Longest Harmonious SubsequenceEasyasked at 2 companies
  5. Replace the Substring for Balanced StringMediumasked at 1 companies
  6. Maximum Erasure ValueMediumasked at 1 companies
  7. Minimum Recolors to Get K Consecutive Black BlocksEasyasked at 1 companies
  8. Maximum White Tiles Covered by a CarpetMediumasked at 1 companies
  9. Shortest Subarray With OR at Least K IEasyasked at 1 companies
  10. Shortest Subarray With OR at Least K IIMediumasked at 1 companies

Everything in the app, in one place.

Practice, interviews and the tools, all free to start. Swipe to see the rest.

Free to start: 100 AI credits when you sign up and 100 every month. Start free in the app

About sliding window problems.

Free to start, no card.

Start practising
How do I know a problem is a sliding window problem?

The answer is the best or longest contiguous run that satisfies a rule.

How many sliding window problems should I solve?

Enough to stop needing the hint, which is usually ten to fifteen across the levels, not the whole list. The catalogue tags 81, split roughly 9 easy, 51 medium and 21 hard in the sample we show, so work up rather than across.

What goes wrong most often in sliding window problems?

Negative numbers. A window argument needs the total to move in one direction as the window grows, and negatives break that, which is where prefix sums take over.

Is practising by pattern better than a problem sheet?

A sheet tells you what to solve. A pattern tells you why those problems sit together, which is the part that carries over to the problem you have not seen. That is why the app files every problem under its pattern.