Data Structures & AlgorithmsHard

For the array [1, 3, 2, 6, 7, 4, 8, 12, 5], how many index pairs i < j have (J[i] + J[j]) divisible by 4?

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

Correct answer: A. 8

Pairs split by residue: two residue-0 values, a residue-1 with a residue-3 value, or two residue-2 values. The residue-2 class contributes C(c2, 2), so dropping it or squaring c2 gives the wrong total, and ordered pairs double the count.

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

Exams that ask this topic