Data Structures & AlgorithmsHard

How many contiguous subarrays of 4 7 1 10 5 8 have (maximum − minimum) divisible by 3? (A single element gives 0, which counts as divisible.)

  1. A. 13
  2. B. 2
  3. C. 19
  4. D. 20

Correct answer: C. 19

Zero is divisible by 3, so every singleton qualifies, which matters for the total. Dropping singletons, taking the complement, or using the sum of the extremes gives the wrong set.

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

Exams that ask this topic