AlgoScope

Prefix Sum

AlgorithmbeginnerArray Techniques

Store running totals once, and any range sum becomes two lookups and a subtraction.

Result · step 9 of 11Prefix Sum and Kadane: Range sum from prefix totals
3✓04✓18✓29✓314✓423✓525✓631✓7i

prefix[7] = prefix[6] + a[7] = 25 + 6 = 31.

Open in the player →or start at step 9

What you will see

A second row fills left to right; a range query highlights two prefix cells and their difference.

How prefix sum and kadane works →

Cost

BestO(n)
AverageO(n)
WorstO(n)
SpaceO(n)

O(1) per query after O(n) build.

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.

Screen readers: Each cell is announced as index, value and state; each step's accessibility text states the decision and its effect.

Reduced motion: Swaps and shifts become value crossfades with an outline flash; pointers appear at their destination.

Before this

Taught by the same lesson

Prefix Sum and Kadane covers these too, in the same run.