Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA

How many index pairs i < j of [1, 2, 3, 4, 5, 6] have a product strictly less than 20?

  1. A. 13
  2. B. 15
  3. C. 12
  4. D. 9

Correct answer: C. 12

Two pointers on the sorted values count, for each left value, the right values keeping the product below 20: 5 (with 1) + 4 (with 2) + 3 (with 3) = 12. Allowing products equal to 20 (4 × 5) gives 13, 15 counts all pairs and 9 counts only the pairs that use 1 or 2.

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

Exams that ask this topic