← 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:
- A.P[r] − P[l]
- B.P[r + 1] − P[l]
- C.P[r] − P[l − 1]
- 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 →