Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

From the numbers [17, 22, 9, 35, 41, 13, 28], choose a subset (each number used at most once) whose sum is as large as possible without exceeding 60. What is that maximum sum?

  1. A. 39
  2. B. 0
  3. C. 60
  4. D. 59

Correct answer: D. 59

This is subset-sum DP: track all reachable sums not exceeding S and take the largest. Greedily adding the smallest numbers first gives a smaller total, and choosing the largest numbers first can block a better combination.

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

Exams that ask this topic