Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

From the multiset [6, 1, 4, 2, 5, 3], choose as many elements as possible (order irrelevant) with total at most 10. What is the maximum count?

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

Correct answer: B. 4

Take the smallest elements first; the exchange argument shows this maximises the count for a sum bound. Here 1, 2, 3 and 4 sum to 10.

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

Exams that ask this topic