Data Structures & AlgorithmsHardGATE CS · TCS NQT

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

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

Correct answer: C. 4

Two subarrays with equal prefix-sum residues mod 5 differ by a subarray whose sum is divisible by 5, so count pairs of equal residues among the prefix sums (including the empty prefix).

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

Exams that ask this topic