← Quiz: Prefix Sums and Difference Arrays: all 13 questions
Quiz: Prefix Sums and Difference Arrays · Question 6 of 13
m range updates on an array of n elements with a difference array cost:
m range updates on an array of n elements with a difference array cost:
- A.O(n · m)
- B.O(n + m)
- C.O(m log n)
- D.O(n²)
Answer & explanation
Correct answer: O(n + m)
Each update is two O(1) writes; one O(n) running sum at the end builds the final array.
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 →