Sliding Window Visualizer

Step through fixed and variable sliding window patterns, inspect left and right boundaries, and see how the running sum creates the final answer.

Values
6
Window
0
Sum
0
Best
-

Array input

Step controls

Step 1 of 8: Start fixed-size window with k = 3.

Window diagram

Start fixed-size window with k = 3.

Window Moved Best
2
0
L
1
1
5
2
1
3
3
4
2
5

Current state

Left: 0

Right: -1

Window sum: 0

Best: none yet

Window values

No active window yet.

What is a Sliding Window Visualizer?

A sliding window visualizer shows how an algorithm keeps a moving range over an array. The window has a left boundary, a right boundary, and a running value such as a sum or length.

This tool includes fixed-size maximum sum and variable-size minimum subarray length examples. It is useful for learning subarray problems, two-boundary logic, and coding interview patterns.

For the full cluster of related tools, browse the Data Structure Visualizers hub.

How to use this sliding window visualizer

  • Paste an array such as [2, 1, 5, 1, 3, 2].
  • Choose fixed-size or variable-size window mode.
  • Set the window size or target sum.
  • Step through each expand, shrink, and best-result update.
  • Compare the highlighted window with the running sum and best answer.

Sliding window vs two pointers

Sliding window usually keeps a continuous range and updates a running value as the range expands or shrinks. Two pointers can also use left and right indexes, but the pointers may move toward each other rather than preserving a window.

Compare this page with the Two Pointers Visualizer, Sorting Algorithm Visualizer, and Matrix Traversal Visualizer.

Frequently Asked Questions

What input format does this sliding window visualizer use?
Paste an array, comma-separated list, or space-separated list of numbers.
What is fixed-size sliding window?
Fixed-size sliding window keeps the same number of items in the window and moves it one index at a time.
What is variable-size sliding window?
Variable-size sliding window expands and shrinks based on a condition, such as reaching a target sum.
Can I use negative numbers?
Fixed-size mode supports negative numbers. Variable target-sum mode is designed for non-negative numbers because the standard shrink rule depends on sums increasing as the window expands.

Related tools