Range sums

Write code · Medium · §3.2 Shifting and ranges

You are given a list of integers nums and a list of ranges queries. Each element [s, e] of queries is the range from nums[s] to nums[e] (both ends included).

Complete the function solution, which finds the sum of each range and returns the sums in a list, in the same order as queries.

Function

solution(nums, queries)

Constraints

Examples

numsqueriesresult
[1, 2, 3, 4, 5][[1, 3], [0, 4]][9, 15]
[10, -3, 7][[1, 1], [0, 1]][-3, 7]

Starter code

def solution(nums, queries):
    answer = []
    return answer

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.