🎙 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 12 of 13

In a 2D prefix sum query, why is P[r1][c1] ADDED back?

In a 2D prefix sum query, why is P[r1][c1] ADDED back?

  1. A.It is the answer itself
  2. B.The top-left block was subtracted twice, once with the rows above and once with the columns to the left
  3. C.To convert the sum to an average
  4. D.It is a mistake; it should be subtracted
Answer & explanation

Correct answer: The top-left block was subtracted twice, once with the rows above and once with the columns to the left

Inclusion–exclusion: remove the strip above and the strip to the left, then add back their overlap.

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 →