Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.

Try one problem
0
Concept

Overview

What a sliding window is · the fixed-size flavor
step 1 / 8
2
4
1
5
3
6
2
[0][1][2][3][4][5][6]
Concept
1// Fixed-size window (size K):
2window = arr[0..K)
3for r ← K to n − 1:
4 drop arr[r − K], add arr[r] // O(1) slide
5 update the answer
state
  • n7

line 1A sliding window is a contiguous sub-range [L, R] of the array. We slide it through the array — adding what enters on the right, removing what leaves on the left — updating our answer as it moves.