ARCESIUM OA 2022 | Range Sum Query 2D | Mutable (2D Binary Indexed Tree / Fenwick Tree)
Question · Posted Jun 2026
Problem Statement You are given a 2D matrix of integers. Design a data structure that supports the following operations efficiently: update(row, col, val) Update the value of the cell at position (row, col) to val. sumRegion(row1, col1, row2, col2) Return the sum of all elements inside the rectangle defined by: Top-left corner: (row1, col1) Bottom-right corner: (row2, col2) The solution should support multiple updates and queries efficiently. Example Input Matrix = [ [3,0,1,4,2], [5,6,3,2,1], [1,2,0,1,5], [4,1,0,1,7], [1,0,3,0,5] ] sumRegion(2,1,4,3) update(3,2,2) ...
The full answer & interview discussion are available to premium members.
Log in Create a free account