Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA

Arrays A = [2, 3, 5, 7, 4] and B = [6, 10, 1, 3, 8]. How many pairs (x in A, y in B) satisfy x * y = 24?

  1. A. 4
  2. B. 1
  3. C. 11
  4. D. 2

Correct answer: D. 2

For each x, the required partner is P / x when it is an integer; a hash set of B makes each lookup O(1). Checking the product bound instead of equality counts a larger set of pairs.

More Coding Interview Problems questions

Exams that ask this topic