medium
Range Sum Query — Mutable
Design a structure over an integer array supporting two interleaved operations: update(i, v) sets element i to v, and sumRange(l, r) returns the sum of elements from l to r inclusive. Both must be fast for large numbers of calls.
Constraints
- 1 ≤ n ≤ 3 · 10^4
- -100 ≤ nums[i] ≤ 100
- At most 3 · 10^4 calls to update and sumRange
Examples
in: nums = [1,3,5]; sumRange(0,2), update(1,2), sumRange(0,2)
out: 9, 8
Code it yourself
Solve in
Test execution is not yet available for this exercise.Practice journal →Draft saved in this browser.
Hints:
Which approach applies?
Choose an approach to check your pattern recognition, or reveal the discussion when you need help.