dsa · easy

Range Sum Queries (Prefix Sum)

GreyOrangeArrayFoundation

nums and queries where each query is [l, r] inclusive. Return the sum of nums[l..r] for every query.

Arguments

**Example:** nums=[1,2,3,4], queries=[[0,1],[1,3]][3,9].

Constraints

1 <= nums.length <= 4*10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[1,2,3,4]
[[0,1],[1,3]]

Expected:
[3,9]

Open in the Dojo editor