Data Structures & AlgorithmsHard

For [2, 3, 4, 6, 9, 5, 12], how many index pairs i < j have the product BB[i]·BB[j] divisible by 6?

  1. A. 15
  2. B. 6
  3. C. 17
  4. D. 18

Correct answer: A. 15

A product is divisible by 6 when it has a factor 2 and a factor 3, and those may come from different elements. Requiring both elements to be multiples of 3 misses many valid pairs, and including i = j double-counts self-pairs that are not pairs of distinct positions.

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

Exams that ask this topic