Code Room
CodingEasycod-g1290
Subject Prefix sumLevel Entry–Mid~12 minCommon in Databases & SQL · Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.