Prefix Sum Quiz
Editorial
13 questions across the three Prefix Sum lessons: which kind of running total a task needs, what the hash map holds, what each step of a template does, and what a small bug does. Pick an answer to see whether it's right and why. Nothing is saved, so you can take it again.
If one trips you up, its lesson is Introduction to Prefix Sums, Prefix Sums with a Hash Map or Difference Arrays and 2D Prefix Sums.
Quiz
1 / 13Multiple choice
An array never changes, and you'll be asked for the sum of nums[l..r] thousands of times. What do you build?
Multiple choice
Count the subarrays that add up to exactly k, where values can be negative. What do you use?
Multiple choice
Ten thousand updates each add v to a range of indexes, and the array is read once at the end. What do you use?
Multiple choice
A matrix never changes, and you'll be asked for the sums of many rectangles. What do you build?
Multiple choice
P holds the running totals of nums with a 0 in front. Which is the sum of nums[2..5]?
Multiple choice
Python, running totals without the 0 in front, and a range is prefix[right] − prefix[left − 1]. What does sumRange(0, 2) return on [4, -2, 7, 1, 9]?
Multiple choice
Subarray Sum Equals K: why does the map count how many times each total appeared, instead of only whether it did?
Multiple choice
Subarray Sum Equals K with the map starting empty instead of {0: 1}, on [1, 2, -1, 2, -2, 3, -1, 2] with k = 3 (the answer is 6). What does it return?
Multiple choice
In Java, what is -7 % 5?
Multiple choice
Continuous Subarray Sum on [1, 0, 0] with k = 2, where the map moves each remainder to its latest index. What happens?
Multiple choice
Range Addition writes diff[end] −= inc instead of diff[end + 1]. What does it return for 5 zeros and the update [1, 3, 2]?
Multiple choice
Car Pooling: riders get on at from and are off at to. Where does −passengers go?
Multiple choice
Why do running XORs answer "XOR of nums[l..r]" the way running sums answer range sums?