Recall & Review
beginner Click to reveal answer
What is a Prefix Sum Array?
A Prefix Sum Array is a new array where each element at index i is the sum of all elements from the start up to index i in the original array.
beginner Click to reveal answer
How do you compute the prefix sum array for [2, 4, 6, 8]?
Start with the first element: 2. Then add each next element to the sum of all previous elements: [2, 6, 12, 20].
intermediate Click to reveal answer
Why is a prefix sum array useful?
It helps quickly find the sum of any subarray by subtracting prefix sums, reducing repeated addition and improving efficiency.
beginner Click to reveal answer
What is the time complexity to build a prefix sum array of size n?
The time complexity is O(n) because you compute each prefix sum by adding one element at a time in a single pass.
intermediate Click to reveal answer
How to find the sum of elements between indices i and j using a prefix sum array?
Sum from i to j = prefixSum[j] - prefixSum[i-1] (if i > 0), else prefixSum[j] if i = 0.
What does the element at index 3 in a prefix sum array represent?
✗ Incorrect
Each prefix sum element at index i is the sum of all elements from start up to i.
What is the time complexity to answer sum queries using a prefix sum array?
✗ Incorrect
Once prefix sums are built, sum queries between any two indices can be answered in constant time.
If prefixSum = [3, 7, 12, 18], what is the sum of elements from index 1 to 3?
✗ Incorrect
Sum = prefixSum[3] - prefixSum[0] = 18 - 3 = 15.
Which of the following is NOT a benefit of using prefix sum arrays?
✗ Incorrect
Prefix sum arrays use extra memory equal to the original array size.
How do you initialize the first element of a prefix sum array?
✗ Incorrect
The first prefix sum element equals the first element of the original array.
Explain how to build a prefix sum array from a given array.
Think about adding elements one by one to the sum of all before.
You got /3 concepts.
Describe how prefix sum arrays help in finding the sum of any subarray quickly.
Consider how subtraction of prefix sums gives subarray sums.
You got /3 concepts.
