Skip to content
Optimal Lab

DSA · interactive

Sliding window

Find the 3 adjacent cells with the biggest sum. The first window is added in full. Every later window only drops the cell that left and adds the cell that entered.

Window 1 of 5

best 8 at cell 0

  1. 2
  2. 1
  3. 5
  4. 1
  5. 3
  6. 2
  7. 4

sum = 8

Adds so far: sliding 3, re-adding every cell 3.

First window: add all 3 cells. Sum 8.

  1. 1

    k is how many adjacent cells you look at together.

    k = 3, so there are 5 window positions. Change k in the panel.

  2. 2

  3. 3

  4. 4

  5. 5

In production

Tools and technologies

Fixed windows are implemented with arrays or deques in memory — the technique, not a vendor SKU.

Not tied to one language — use these names when you search docs or design a system.