FunctionRacerProblemsRace

Range Sum Queries

EasyArraysPython, JavaScript, TypeScript, Java, C++

Each item of queries is a pair [left, right]. For each query, in order, compute the sum of the items of nums from nums[left] through nums[right], both ends included.

Return the list of answers. Hint: a prefix-sum list makes each query fast.

Example 1

nums [1,2,3,4,5]
queries [[0,2],[1,3]]
returns [6,9]

1+2+3 = 6, and 2+3+4 = 9.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Arrays problems