Prefix Sums
6 min · C# examples
Precompute running totals so any range sum becomes a quick subtraction.
C# · Prefix Sums0/5 cleared
Enemy 1 of 5
A prefix sum at index i stores the total of everything from the start up to i. Build it once, then the sum of any slice [L..R] is prefix[R] - prefix[L-1].
This turns repeated range-sum questions from O(n) each into O(1) each after O(n) setup.
You
Cold-Start Frostling
Loading editor...
Ln 1, Col 1Spaces: 4
Sign up to fightTarget output: 10