🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Prefix Sums and Difference Arrays: questions with answers

13 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. What does this print? (code)
  2. Q2. With a prefix array P that starts with 0, the sum of a[l..r] (inclusive) is:
  3. Q3. Why can't a sliding window count subarrays with sum k when the array has negative numbers?
  4. Q4. In the prefix-sum + hash map method, why do we start with seen = {0: 1}?
  5. Q5. What does this print? (code)
  6. Q6. m range updates on an array of n elements with a difference array cost:
  7. Q7. In a 2D prefix sum, why is P[i][j] subtracted when building P[i + 1][j + 1]?
  8. Q8. Updates and range-sum queries come mixed together, 10⁵ of each. What do you need?
  9. Q9. What does this print? (code)
  10. Q10. What does this print? (code)
  11. Q11. Why is the difference array one cell longer than the result?
  12. Q12. In a 2D prefix sum query, why is P[r1][c1] ADDED back?
  13. Q13. An array never changes and you must answer 10⁵ "sum of a[l..r]" queries. What is the total cost with prefix sums?