Data Structures & AlgorithmsHardTCS NQT · Codeforces Div2 C

What is the length of the longest subsequence (any positions, keeping order) of [2, 3, 5, 1, 4] whose product is at most 12?

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

Correct answer: A. 3

Since all values are positive, multiplying in more numbers can only increase the product, so the best subsequence takes the smallest values first. Taking elements in order without sorting can exclude a smaller set that fits.

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

Exams that ask this topic