← Quiz: Prefix Sums and Difference Arrays: all 13 questions
Quiz: Prefix Sums and Difference Arrays · Question 4 of 13
In the prefix-sum + hash map method, why do we start with seen = {0: 1}?
In the prefix-sum + hash map method, why do we start with seen = {0: 1}?
- A.To avoid dividing by zero
- B.So that subarrays starting at index 0 are counted
- C.Because Python dictionaries can't be empty
- D.To make the answer one bigger
Answer & explanation
Correct answer: So that subarrays starting at index 0 are counted
A subarray a[0..r] has sum k when the running total equals k, which matches the empty prefix with sum 0.
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 →