Skip to content

Sliding Window

Look at a long train through a window: when it moves one carriage enters and one leaves, and you never recount the whole train. For problems about a contiguous subarray or substring, you grow the window on the right and shrink it on the left while keeping a small running summary.

After this topic: You can maintain a valid window with a counter, set or map and decide when to record the best answer.

Do these first: Two Pointers

0 of 6 solved0%

Step 1 · Read the lesson

Sliding Window

Keep a moving range valid and update it incrementally instead of recomputing.

Step 2 · Solve the problems in order

Try each one for about 20 minutes first. Problems with a Run code tab are checked right here. If you are stuck, open Nudge, think again, then Idea. Go skeleton only gives the function shape, and Reference solution is for comparing after you have tried. Tick the box when you could solve it again without help.

  1. 1.Best Time to Buy and Sell StockEasy
  2. 2.Longest Substring Without Repeating CharactersMedium
  3. 3.Longest Repeating Character ReplacementMedium
  4. 4.Permutation in StringMedium
  5. 5.Minimum Window SubstringHard
  6. 6.Sliding Window MaximumHard