Data Structures & AlgorithmsVery hardAmazon OA · Arrays

How many pairs of positions (i < j) in [5, 3, 7, 9, 1, 2, 6, 10, 14, 4] have a[i] + a[j] divisible by 4?

  1. A. 12
  2. B. 10
  3. C. 14
  4. D. 16

Correct answer: A. 12

Residues mod 4: three 1s, two 3s, four 2s and one 0. Pairs 1+3 give 3 x 2 = 6, pairs of 2s give C(4,2) = 6, the single 0 pairs with none: 12.

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

Exams that ask this topic