← Quiz: Prefix Sums and Difference Arrays: all 13 questions
Quiz: Prefix Sums and Difference Arrays · Question 11 of 13
Why is the difference array one cell longer than the result?
Why is the difference array one cell longer than the result?
- A.To store the total sum at the end
- B.Because Python lists start at 1
- C.An update that ends at the last index writes d[r + 1], which is one past the end
- D.To keep a copy of the original array
Answer & explanation
Correct answer: An update that ends at the last index writes d[r + 1], which is one past the end
With r = n − 1, d[r + 1] = d[n] must exist, even though it is never added into the result.
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 →