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

Array [4, 7, 1, 9, 3, 6, 2, 5]. How many pairs of prefix indices (i < j) among the nine prefix sums (including the empty prefix) have a difference divisible by 10?

  1. A. 6
  2. B. 1
  3. C. 32
  4. D. 4

Correct answer: D. 4

Two prefix sums differ by a multiple of 10 exactly when they have the same remainder mod 10, so count the remainder classes and add C(c, 2) for each. The empty prefix is one of the nine prefixes and must be included.

More Coding Interview Problems questions

Exams that ask this topic