← 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?
- A.It is the answer itself
- B.The top-left block was subtracted twice, once with the rows above and once with the columns to the left
- C.To convert the sum to an average
- 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 →