Data Structures & AlgorithmsModerate

How many contiguous subarrays of [3, 1, 4, 1, 5, 9, 2, 6] have a sum that is divisible by their own maximum element?

  1. A. 33
  2. B. 11
  3. C. 3
  4. D. 4

Correct answer: B. 11

The divisibility test uses the subarray's own maximum, found by scanning the block; dividing by the minimum or by the length tests different quantities. Excluding single elements drops the trivially divisible blocks, which must be counted.

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

Exams that ask this topic