Data Structures & AlgorithmsHardTCS NQT · GATE CS

Coins of value 2, 3 and 7 are available in unlimited supply. What is the minimum number of coins needed to make exactly 20?

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

Correct answer: A. 4

DP over amounts: dp[v] = 1 + min over coins c ≤ v of dp[v − c]. The minimum is four coins (7 + 7 + 3 + 3). A DP over amounts, dp[v] = 1 + min dp[v − c], finds this exactly, whereas a rule that fixes the number of 7s first (for example 20 // 7 = 2 and then 6 more) can miss the cheapest split.

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

Exams that ask this topic