Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

What is the length of the longest contiguous subarray of [2, 0, 0, 2, 0, 2, 2] whose sum is 0?

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

Correct answer: D. 2

Store the first index of each prefix sum (seed 0 at index -1); the longest zero-sum window is the one between equal prefix values with the largest gap.

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

Exams that ask this topic