Skip to content

Glossary: Coding Interviews in C++

Prefix sum

Also written: prefix sums, prefix vector

A vector of running totals where `prefix[i]` is the sum of the first i items, so any range total is one subtraction, `prefix[end] - prefix[start]`. Setup is O(n), then each question is O(1).

Where the book teaches it

Related terms

Sliding window