Skip to content
DSA Visualizerpreview

Maximum sum window of size k

Slide a window of k values along the array, updating its sum in O(1) per step.

O(n) time · O(1) space

Values2, 1, 5, 1, 3, 2, 6, 1k 3

Sum the first window of 3: 2, 1, 5 = 8.

Array of 8 values: 2, 1, 5, 1, 3, 2, 6, 1. Active index 0 (2) and index 2 (5). Pointers l at index 0 and r at index 2.
  • compare
  • swap or write
  • settled

1 / 7

Speed

Space play · ← → step · Home End jump · drag the strip to scrub