Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

How many contiguous subarrays of [2, 4, 6, 8] have every element divisible by 4?

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

Correct answer: C. 2

Split the array at elements not divisible by 4 and count subarrays within each run: here only the single element 4 and 8 qualify, plus nothing else, so there are 2.

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

Exams that ask this topic