Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA

Problem: In the array [1, −2, 3, −4, 5, −6], how many contiguous subarrays have a sum of exactly 0?

  1. A. 1
  2. B. 0
  3. C. 2
  4. D. 3

Correct answer: B. 0

Brute force over subarrays with running sums checks each one. Prefix sums with a hash map give the same count, since subarrays summing to zero have equal boundary prefix sums.

More Coding Interview Problems questions

Exams that ask this topic