Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many contiguous subarrays of [7, 1, 6, 13, 8, 2] have a sum congruent to 0 modulo 7?

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

Correct answer: C. 6

Use a count of prefix residues mod 7: each pair of equal residues among prefixes (with the zero prefix) contributes one subarray with sum 0 mod 7.

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

Exams that ask this topic