Once you have the prefix array, queries are trivial: plaintext function sumRange(left, right) return prefix[right + 1] - prefix[left] Time: . Space: per query. The offset handles the convention that is the sum of elements before index . If this feels awkward, trace through an example until it clicks.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/data-structures/arrays-prefix-sums/range-sum-answering-queries
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████████████████████████████████████████████████████████████████████████████████████████