Range Sum Queries
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
1 <= len(nums) <= 1000 <= len(queries) <= 500 <= left <= right < len(nums)
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.