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