Data Structures & AlgorithmsModerateTCS NQT · Infosys

Arrays A = [2, 5, 3, 7] and B = [4, 6, 1, 9]. How many pairs (x from A, y from B) satisfy 10 <= x * y <= 40?

  1. A. 13
  2. B. 16
  3. C. 8
  4. D. 11

Correct answer: C. 8

Of the 16 products, those in [10, 40] are 12, 12, 18, 18, 20, 27, 28, 30: 8 pairs (sorting B and binary searching each x does it in O(n log n)). Dropping the lower bound gives 13, dropping the upper bound gives 11, and 16 counts every pair.

More Coding Interview Problems questions

Exams that ask this topic