As we approach the festive season, many businesses analyze their daily sales to make smart decisions. In this problem, you'll use the prefix sums technique to quickly answer range sum queries over an array of daily sales figures.
You are given an array of integers arr
where each element represents the sales amount on a particular day leading up to the holidays. Additionally, you are given a list of queries. Each query is a pair of integers [L, R]
(inclusive) representing the start day and end day respectively. Your task is to implement a function to return a list of sums where each sum is the total sales from day L
to day R
.
arr
of length n
.[L, R]
(0-indexed).arr[L]
to arr[R]
for the corresponding query.For example, given the array:
arr = [3, 2, 4, 5, 1]
And queries:
queries = [[1, 3], [0, 4]]
The output should be:
[11, 15]
Explanation:
2 + 4 + 5 = 11
.3 + 2 + 4 + 5 + 1 = 15
.Below is some language-agnostic starter code to help you get started with your solution.