Data Structures & AlgorithmsVery hardTCS NQT · Infosys

How many index pairs i < j in [1, 4, 7, 2, 5, 8] satisfy that a[i] - a[j] is divisible by 3?

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

Correct answer: B. 6

Two values have a difference divisible by 3 exactly when they share a residue mod 3, so group by residue and add the pair counts.

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

Exams that ask this topic