Data Structures & AlgorithmsModerate

How many contiguous subarrays of 2 4 3 6 1 5 have a sum that is divisible by the number of DISTINCT values in them?

  1. A. 10
  2. B. 11
  3. C. 2
  4. D. 9

Correct answer: A. 10

Compute the distinct count of each subarray first, then test the sum against it. Using the length instead of the distinct count, or the complement, changes which blocks qualify.

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

Exams that ask this topic