Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B

How many index pairs i < j in the array [1, 2, 3, 1, 2, 3] make a[i] * a[j] = 6?

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

Correct answer: A. 4

Products of 6 come from 2 with 3 and from 1 with 6 (absent here). Count the matching pairs by hashing the complement 6 / x for each x.

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

Exams that ask this topic