Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT

Over all pairs of DIFFERENT positions of [2, 5, 3, 8, 4], take the product of each pair and sort all these products. What is the 6-th smallest product (with multiplicity)?

  1. A. 15
  2. B. 20
  3. C. 16
  4. D. 17

Correct answer: C. 16

Binary search the product value x, counting pairs with product ≤ x by a two-pointer sweep over the sorted array; the smallest x with count ≥ k is the answer. Taking the k-th pair in input order, or the k-th largest, gives a different value.

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

Exams that ask this topic