Data Structures & AlgorithmsVery hardGATE CS

How many non-empty contiguous subarrays of [5, 2, -3, 8, 6, -9, 4, 7, 1, 3, 12, -5, 6, 2] have a sum divisible by 7?

  1. A. 10
  2. B. 12
  3. C. 15
  4. D. 8

Correct answer: A. 10

Using prefix sums mod 7 (Python-style non-negative remainders), the number of equal prefix-remainder pairs is 10. Using the language remainder for negatives would mix up classes.

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

Exams that ask this topic