AlgoScope

Range Sum Query

AlgorithmbeginnerArray Techniques

The sum of a range is the total up to its end minus the total before its start.

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

Two prefix cells light up; the answer is their difference.

How prefix sum and kadane works →

Cost

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

After O(n) preprocessing.

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.