Data Structures & AlgorithmsHard

How many index triples i < j < k in 1 2 3 4 5 6 7 have A[i] + A[j] + A[k] divisible by 3?

  1. A. 13
  2. B. 11
  3. C. 7
  4. D. 25

Correct answer: A. 13

Enumerate the index triples and test the residue of their sum mod 3; the residue classes of 1, 2, 0 mix in a balanced way here. Using pairs, a different residue, or the product condition each answer another question.

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

Exams that ask this topic