MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / RangeSum

Method RangeSum

structure/fenwicktree/fenwicktree.go:50–52  ·  view source on GitHub ↗

RangeSum returns the sum of the elements in the range l to r both inclusive.

(l int, r int)

Source from the content-addressed store, hash-verified

48// RangeSum returns the sum of the elements in the range l to r
49// both inclusive.
50func (f *FenwickTree) RangeSum(l int, r int) int {
51 return f.PrefixSum(r) - f.PrefixSum(l-1)
52}
53
54// Add Adds value to the element at position pos of the array
55// and recomputes the range sums.

Callers 1

TestFenwickTreeFunction · 0.95

Calls 1

PrefixSumMethod · 0.95

Tested by 1

TestFenwickTreeFunction · 0.76