Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional

Including the empty prefix (sum 0), how many of the prefix sums of [3, 1, 4, 2, 6, 5, 3, 1] are divisible by 4?

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

Correct answer: A. 5

Prefix sums are running totals; the empty prefix counts because 0 is divisible by 4. Dropping the empty prefix undercounts by exactly one.

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

Exams that ask this topic