Example 1 · empty
- Arguments
- values
[]
queries[]
- Expected return
[]
Test data
- Input
{"values":[],"queries":[]}- Expected output
[]
func RangeSums(values []int, queries [][2]int) []intExamples use {"values": [...], "queries": [[start, end], ...]}.
The runner calls your functions directly; you do not need to parse JSON.
[]
[]
[]
{"values":[],"queries":[]}[]
[ 4, -2, 7, 1 ]
[
[
0,
4
],
[
1,
3
],
[
2,
2
]
][ 10, 5, 0 ]
{"values":[4,-2,7,1],"queries":[[0,4],[1,3],[2,2]]}[10,5,0]
[]
[
[
0,
0
],
[
0,
0
]
][ 0, 0 ]
{"values":[],"queries":[[0,0],[0,0]]}[0,0]
[ -3, 5, -1 ]
[
[
1,
3
],
[
0,
1
],
[
1,
3
]
][ 4, -3, 4 ]
{"values":[-3,5,-1],"queries":[[1,3],[0,1],[1,3]]}[4,-3,4]
prefix[end] totals exactly the values before end. Subtracting prefix[start] removes the values before start, leaving precisely indices start through end - 1. The leading zero makes ranges starting at zero and empty ranges obey the same formula.
O(n + q) total time for n values and q queries, with O(n) auxiliary prefix storage excluding the O(q) returned sums. Use an integer type covering the stated sum bounds.
Checking execution availability…
View inputs and expected outputs. Examples do not run your code.