Algorithms and Data Structures · Junior · Question 67 of 75

What is a prefix sum array?

Explanation

After one O(n) pass, the sum of any range [l, r) is prefix[r] - prefix[l] in O(1). It's the go-to trick when the same array is queried for many range sums.

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 67

Test yourself

Take the Algorithms and Data Structures · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz