Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C

Coins of values 1, 4, 9 and 16 are available in unlimited supply. What is the minimum number of coins that makes exactly 27?

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

Correct answer: A. 3

Unbounded coin-change DP: dp[v] = 1 + min dp[v − c] over the four coins. Greedy largest-first is not guaranteed here: it uses 16 + 9 + 1 + 1 = 4 coins while 9 + 9 + 9 uses 3.

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

Exams that ask this topic