Range sums
Write range_sums(items, queries) where queries is a list of (i, j)
pairs with i <= j. Return a list with, for each query, the sum of
items[i] through items[j] inclusive.
range_sums([3, 1, 4, 1, 5], [(0, 2), (1, 3), (4, 4)]) -> [8, 6, 5]
range_sums([3, 1, 4, 1, 5], []) -> []
The point is to practise prefix sums. One check has a hundred thousand items and a hundred thousand queries; summing each range directly is billions of steps and will not finish in time.
def range_sums(items, queries):
...