Data Structures & AlgorithmsHardProduct Company SDE · ICPC regional

Problem: A 2D prefix-sum table is built for the grid [[1,2,3],[4,5,6],[7,8,9]]. What is the sum of the submatrix with rows 1–2 and columns 0–1 (0-indexed, inclusive)?

  1. A. 27
  2. B. 24
  3. C. 39
  4. D. 28

Correct answer: B. 24

With prefix sums P, the block sum is P[2][1] − P[0][1] = 27 − 3 = 24, i.e. 4 + 5 + 7 + 8. Forgetting to subtract row 0 gives 27, extending to column 2 gives 39, and shifting to columns 1-2 gives 28.

More Coding Interview Problems questions

Exams that ask this topic