Given a fixed array and a list of [left, right] range queries, return the sum of each range. DeepLogic's adaptation asks for every query's answer at once, in a single call, rather than modeling repeated method calls on a stored object.
Example 1
Explanation: Each query's sum is read off the same precomputed prefix array in O(1): indices 0-2 sum to 1, 2-5 sum to -1, and the whole array sums to -3.
Example 2
Explanation: A single query still uses the same prefix array: indices 1-3 are 2 + 3 + 4 = 9.
Example 3
Explanation: Query [2,2] is a single-element range (just nums[2] = 3), and [1,3] shows the sum can be 0 even with nonzero elements on both signs.
How would the approach change if nums could be updated between queries — what would break about the O(1)-per-query guarantee?
Code execution is coming soon.