🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Prefix Sums and Difference Arrays: all 13 questions

Quiz: Prefix Sums and Difference Arrays · Question 7 of 13

In a 2D prefix sum, why is P[i][j] subtracted when building P[i + 1][j + 1]?

In a 2D prefix sum, why is P[i][j] subtracted when building P[i + 1][j + 1]?

  1. A.It is the cell being added
  2. B.The top-left rectangle is counted twice — once in the cell above and once in the cell to the left
  3. C.To keep the values small
  4. D.It isn't needed; it is a mistake
Answer & explanation

Correct answer: The top-left rectangle is counted twice — once in the cell above and once in the cell to the left

This is inclusion–exclusion: the overlap of the two rectangles must be removed once.

Can you get the rest right without peeking?

Take the timed Quiz: Prefix Sums and Difference Arrays quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →