Data Structures & AlgorithmsHardGATE CS · ICPC regional

How many index triples i < j < k in the array [1, 2, 3, 4, 5, 6] have a[i] + a[j] + a[k] divisible by 5?

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

Correct answer: C. 4

Count residues mod 5 and combine residue classes whose sums are 0 mod 5 (for example 0+0+0, or 1+2+2). Counting by values alone is slower and error-prone.

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

Exams that ask this topic