FastPrepRange Sum Query in a Mutable Grid
Problems/Range Sum Query in a Mutable Grid

Range Sum Query in a Mutable Grid

Bloomberg LP logoBloomberg LP● HardNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A junior-level report from Bloomberg says the first round of its final interview day had an object-oriented task and this coding task: give the sums of rectangles in a grid whose cells can change. The author used prefix sums rather than Fenwick trees and says the interviewer was nearly satisfied. No example, limits or input format is given.

Our choices: the grid and a list of operations come in one call; an update replaces a cell's value; a rectangle is given by its top-left and bottom-right cells, both included; the answer lists the rectangle sums in order. A grid has up to 100 rows and 100 columns with values from -1,000 to 1,000, and there are up to 1,000 operations.

The judged task matches the report at about 85%.

You are given an m x n grid of integers matrix. Rows and columns are numbered from 0. You also get a list of operations to run in order: operations[i] is the name of operation i, and arguments[i] holds its numbers.

  • "update" with [row, col, val]: set the cell in row row and column col to val. The old value is replaced, not added to.
  • "sumRegion" with [row1, col1, row2, col2]: add up every cell of the rectangle whose top-left cell is in row row1, column col1 and whose bottom-right cell is in row row2, column col2. The rows and columns of both corners are included.

Each "sumRegion" uses the grid as it is at that moment, after every earlier update. Return a list with the result of every "sumRegion" operation, in the order they run. If there is none, return an empty list.

Function

numMatrix(matrix: int[][], operations: String[], arguments: int[][]) → int[]

Examples

Example 1

matrix = [[2,-1,4],[0,3,5]]operations = ["sumRegion","update","sumRegion","sumRegion"]arguments = [[0,0,1,1],[1,1,-2],[0,0,1,1],[0,1,1,2]]return = [4,-1,6]
matrix
01202-141035

The first rectangle covers rows 0 to 1 and columns 0 to 1: 2 + (-1) + 0 + 3 = 4.

The update sets the cell in row 1, column 1 from 3 to -2. Now the same rectangle is 2 + (-1) + 0 + (-2) = -1.

The last rectangle covers rows 0 to 1 and columns 1 to 2: (-1) + 4 + (-2) + 5 = 6. The answer is [4,-1,6].

Example 2

matrix = [[7]]operations = ["update","update","sumRegion"]arguments = [[0,0,1],[0,0,-9],[0,0,0,0]]return = [-9]
matrix
007

Each update replaces the value; it does not add to it. After both updates the only cell holds -9, so the answer is [-9].

Example 3

matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]operations = ["sumRegion","sumRegion"]arguments = [[1,2,2,3],[0,0,2,0]]return = [38,15]
matrix
0123012341567829101112

Rows 1 to 2 and columns 2 to 3 hold 7, 8, 11 and 12, which add up to 38. Column 0 of every row holds 1, 5 and 9, which add up to 15. The answer is [38,15].

Constraints

  • 1 <= m, n <= 100, where m == matrix.length and n == matrix[i].length
  • Every row of matrix has the same length.
  • -1000 <= matrix[i][j] <= 1000
  • 1 <= operations.length <= 1000
  • arguments.length == operations.length
  • Each operations[i] is "update" or "sumRegion".
  • For "update", arguments[i] = [row, col, val] with 0 <= row < m, 0 <= col < n and -1000 <= val <= 1000.
  • For "sumRegion", arguments[i] = [row1, col1, row2, col2] with 0 <= row1 <= row2 < m and 0 <= col1 <= col2 < n.

More Bloomberg LP Onsite Interview questions

  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Rectangular K-in-a-RowDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Prefix Matrix Products and AutogradOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Out-of-Order Logger Rate LimiterGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Dynamic Fixed-K Score LeaderboardCoinbase · ONSITE INTERVIEWCoinbase interview questions
  • Cats, Rabbits, and Snails Board GameAsana · ONSITE INTERVIEW
  • Dynamic Weighted SamplingCitadel · ONSITE INTERVIEWCitadel interview questions
  • Volunteer Awards: Totals Divisible by KNutanix · ONSITE INTERVIEWNutanix interview questions
  • Maintain a Consistent-Hashing RingCohesity · ONSITE INTERVIEW
  • Tic-Tac-Toe Move WinnersByteDance · ONSITE INTERVIEWByteDance interview questions
  • Restaurant Delivery HeatmapDoorDash · ONSITE INTERVIEWDoorDash interview questions

Bloomberg LP interview experiences

  • Bloomberg SWE Phone Screen and Onsite: 1 Experience
  • Bloomberg SWE Phone Screens with Two Teams: 1 Experience
  • Bloomberg AI Interview, Hiring Level Not Reported: 2 Experiences
  • Bloomberg Experienced SWE AI Coding Interviews: 2 Experiences
  • Bloomberg New Grad AI-Assisted Coding Rounds: 3 Experiences
  • Bloomberg New Grad SWE AI-Assisted Coding Rounds: 1 Experience
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int[] numMatrix(int[][] matrix, String[] operations, int[][] arguments) {
        // Write your code here.
    }
}
Checking account…