Data Structures & AlgorithmsModerateProduct Company SDE · data structures

Problem: In a Fenwick tree over n positions, what is the cost of a range-sum query combined with point updates?

  1. A. O(n) per operation
  2. B. O(log n) per operation
  3. C. O(1) per operation
  4. D. O(n log n) per operation

Correct answer: B. O(log n) per operation

Both prefix queries and point updates touch O(log n) indices, so a range sum is two prefix sums in O(log n).

More Coding Interview Problems questions

Exams that ask this topic