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

With a prefix array P that starts with 0, the sum of a[l..r] (inclusive) is:

With a prefix array P that starts with 0, the sum of a[l..r] (inclusive) is:

  1. A.P[r] − P[l]
  2. B.P[r + 1] − P[l]
  3. C.P[r] − P[l − 1]
  4. D.P[r + 1] − P[l + 1]
Answer & explanation

Correct answer: P[r + 1] − P[l]

P[r + 1] covers a[0..r] and P[l] covers a[0..l − 1]; their difference is exactly a[l..r].

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 →