Data Structures & AlgorithmsVery hardProduct placement · Amazon/Microsoft

How many pairs (i < j) of [6, 27, 29, 25, 10, 6, 25, 3, 7, 22] have a[i] + a[j] divisible by 6? (Count remainders mod 6 and pair r with 6 − r.)

  1. A. 7
  2. B. 14
  3. C. 4
  4. D. 5

Correct answer: D. 5

Remainder counts: 0→2, 1→3, 2→0, 3→2, 4→2, 5→1. Pairs come from classes r and k − r (C(c, 2) when r = 0 or r = k/2). The total is 5; multiplying c[r]·c[k − r] over all r double-counts and mishandles the self-paired classes.

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

Exams that ask this topic