Data Structures19 sections · 729 units
Open in Course

Problem - Range Sum Query

Classic prefix sum

Given an integer array numsnums, handle multiple queries of the form: what is the sum of elements between indices leftleft and rightright inclusive?

You're solving the textbook prefix sum application. You'll build the prefix array once, then answer each query in constant time. Read the problem statement carefully.

Notice the constraints: up to 10410^4 queries. Without prefix sums, that's 10810^8 operations. With prefix sums, it's 10410^4.