Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

With weight limit 15, what is the maximum number of items from [5, 3, 8, 2, 7, 4] you can carry (choose any subset)?

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

Correct answer: B. 4

Choose the lightest items first: 2 + 3 + 4 + 5 = 14 gives four items, and adding 7 would exceed 15. The greedy by weight is optimal for maximising count.

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

Exams that ask this topic