Range sum queries
Your task
An energy meter records one integer watt-hour value per hour, indexed from 0. An analyst submits a batch of queries, each a pair [l, r] with 0 <= l <= r < number of readings, asking for the total consumption from hour l through hour r inclusive. Return the answers in query order. The batch can be large, so each query should be answered in constant time after one preprocessing pass. Example: readings = [3, 1, 4, 1, 5], queries = [[1, 3], [0, 0]] gives [6, 3].
Examples
consumption_totals(readings: list[int], queries: list[list[int]]) -> list[int]Example 1
Input
consumption_totals([3, 1, 4, 1, 5], [[1, 3], [0, 0]])Output
[6, 3]