Data Structures & AlgorithmsHardCodeforces Div2 B · TCS NQT

How many ordered pairs (i, j) with i ≠ j exist in [2, 4, 3, 8, 6, 9] such that a[j] is divisible by a[i]?

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

Correct answer: D. 6

For each value, count multiples among the others with a double loop (O(n²)) or with frequency counts over multiples. Counting only unordered pairs, or allowing i = j, changes the total.

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

Exams that ask this topic