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

Array a = [2, 3, 5, 1, 4, 5, 2, 3]. How many contiguous subarrays have an even length and a sum divisible by 5?

  1. A. 8
  2. B. 10
  3. C. 7
  4. D. 16

Correct answer: A. 8

Separate the length condition from the sum condition: count subarray pairs whose prefix residues mod 5 match and whose start and end positions have the same parity, using a hash map keyed by (residue, parity).

More Coding Interview Problems questions

Exams that ask this topic