Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2

Coins of denominations [12, 11, 5, 3] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 34? (Coins may be used any number of times; the answer must sum exactly.)

  1. A. 4
  2. B. 3
  3. C. 9
  4. D. 34

Correct answer: B. 3

The unbounded DP gives 3 coins. The greedy largest-first rule uses 4, which is the trap when denominations are not canonical.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic