Data Structures & AlgorithmsHardCAT · Codeforces Div2 B

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

  1. A. 15
  2. B. 16
  3. C. 21
  4. D. 6

Correct answer: A. 15

Test each of the 21 subarrays: 15 have a sum divisible by their length (all 6 single elements included). Checking divisibility by the first element instead gives 16, 21 counts every subarray and 6 counts only the single elements.

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

Exams that ask this topic