Data Structures19 sections · 729 units
Open in Course

Range Sum Query Solution

Implement your solution

Complete the implementation with the recursive helpers for update and query.

Implementation details:

  • Initialize tree size to 4n4n to handle all cases
  • Handle empty array edge case
  • Recursive helpers pass node index and current range

Testing checklist:

  • Single element array
  • Query entire array
  • Update and re-query
  • Multiple updates between queries

Time: O(n)O(n) build, O(logn)O(\log n) update and query. Space: O(n)O(n) for the tree.