Support Dynamic Range Sums
Company: Molocoads
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Quick Answer: This question evaluates knowledge of data structures and algorithmic techniques for range queries and dynamic updates, along with complexity analysis for time and space.
Constraints
- 0 <= left <= right < len(nums)
Examples
Input: ([1, 3, 5], [('sum', 0, 2), ('update', 1, 2), ('sum', 0, 2)])
Expected Output: [9, 8]
Explanation: Fenwick update changes range sum.
Input: ([0], [('sum', 0, 0), ('update', 0, 7), ('sum', 0, 0)])
Expected Output: [0, 7]
Explanation: Single element.
Input: ([2, 4, 6], [('sum', 1, 1)])
Expected Output: [4]
Explanation: Single-index range.
Hints
- A Fenwick tree supports point updates and prefix sums in logarithmic time.