Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

Array a = [4, 2, 6, 1, 5, 3, 3, 9, 2]. How many contiguous subarrays of length at least 3 have a sum divisible by 6?

  1. A. 6
  2. B. 8
  3. C. 5
  4. D. 11

Correct answer: A. 6

Prefix sums with the same remainder mod 6 give divisible subarrays. The length restriction cannot be checked by remainders alone, so a window of length at least 3 is enforced by inserting prefix indices only once they are 3 or more steps behind the current end.

More Coding Interview Problems questions

Exams that ask this topic