2
0
1
1
5
2
1
3
3
4
2
5
4
6
1
7
window sum = 0best = 0
AlgoPlus//structures / sliding-window
Read the theory

Sliding Window · Max Subarray Sum

Slide a fixed window across the array — add one, drop one, never re-scan.

Window k
3
Best sum
0
Legend
Current window
Best window
AI Tutor Workspace
In a nutshell
A sliding window is a slice of neighbouring elements that glides across an array. Instead of recomputing each slice from scratch, you update a running total by adding the value that enters on the right and subtracting the one that leaves on the left — so the entire array is covered in a single pass rather than re-scanning every position.
Ready
Press play to begin the cinematic walkthrough.
Keep a moving window over the array; as it slides, add the entering element and drop the leaving one instead of re-summing.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Sliding Window · Max Subarray Sum.