Code RoomRange sum queries
EasyPrep Room Coding #476

Range sum queries

CodingDatabases & SQLAlgorithms & data structuresEntry–Mid~12 min

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].

Implement
consumption_totals(readings: list[int], queries: list[list[int]]) → list[int]
Examples
in[[3,1,4,1,5],[[1,3],[0,0]]]out[6,3]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 12 min
InputExpectedGot
[[3,1,4,1,5],[[1,3],[0,0]]][6,3]not run yetsample