Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA

Array a = [3, 4, 7, 1, 6, 2, 5, 8]. How many contiguous subarrays have a sum that is divisible by 7?

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

Correct answer: B. 11

The number of subarrays with sum divisible by 7 equals the sum over residue classes of C(count, 2) of the prefix residues, with the empty prefix included. Missing the empty prefix or using the residue-1 class changes the count.

More Coding Interview Problems questions

Exams that ask this topic