Skip to content

Glossary: Coding Interviews

Prefix sum

Also written: prefix sums, prefix

A running-total list where `prefix[i]` is the total of the first `i` items, so any range total is one subtraction: `prefix[end] - prefix[start]`. It costs O(n) to build and O(1) per question.

Where the book teaches it

Related terms

Sliding window