Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional

For the array [1, -1, 2], how many distinct values appear among its prefix sums, counting the empty prefix 0?

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

Correct answer: A. 3

The prefix sums are 0, 1, 0, 2, so 0 repeats and the distinct values are 0, 1, 2. Counting only the non-empty prefixes gives a different number.

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

Exams that ask this topic