Data Structures & AlgorithmsHardProduct-company placement

Coins of denominations 1, 2, 8, 10 are available in unlimited supply. What is the minimum number of coins needed to make 16, and how many coins does the 'largest coin first' greedy method use?

  1. A. Minimum 4, greedy 4
  2. B. Minimum 2, greedy 2
  3. C. Minimum 1, greedy 4
  4. D. Minimum 2, greedy 4

Correct answer: D. Minimum 2, greedy 4

DP: best[a] = 1 + min best[a − c] gives 2; greedy takes the largest coin each time and needs 4. This coin system is not canonical, so greedy fails.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic