Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

How many contiguous subarrays of [3, 4, -7, 1, 2, -6] have a sum of exactly zero?

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

Correct answer: A. 2

A subarray sums to 0 exactly when two prefix sums are equal, so count equal prefix values, including the empty prefix 0.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic