Data Structures & AlgorithmsHardGATE CS · ICPC regional

How many contiguous subarrays of [4, 5, 0, -2, -3, 1] have a sum divisible by 4?

  1. A. 7
  2. B. 4
  3. C. 6
  4. D. 9

Correct answer: C. 6

Count pairs of equal prefix sums modulo 4, including the empty prefix; note that Python's % gives non-negative residues, while C-style remainders can be negative and break the count.

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

Exams that ask this topic