RISHIPAL SINGH · LEARNING LAB

Prefix Sums for Constant-Time Range Totals Explorer

A prefix-sum array stores cumulative totals so a range sum is the difference of two prefix values. Experiment with a small example and see each step update.

If prefix[5] sums the first five values and prefix[2] the first two, indices 2 through 4 sum to prefix[5]-prefix[2].

Read the related guide · · Bookmark this unique URL with Ctrl/Cmd+D.