Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: For the set {2, 3, 4, 6, 8, 9, 12}, how many pairs (x, y) with x < y have x dividing y?

  1. A. 10
  2. B. 17
  3. C. 15
  4. D. 21

Correct answer: A. 10

Pairs x < y with x | y: 2→4, 6, 8, 12; 3→6, 9, 12; 4→8, 12; 6→12, total 10. Counting x | x too gives 17, gcd > 1 gives 15, and 21 counts all pairs.

More Coding Interview Problems questions

Exams that ask this topic