Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: Coins of denominations 5, 12 and 20 are available in unlimited supply. What is the minimum number of coins needed to make exactly 63?

  1. A. 5
  2. B. 7
  3. C. No combination works
  4. D. 4

Correct answer: B. 7

Checking every count of 20s and 12s, 63 = 12 × 4 + 5 × 3 is the only representation, so 7 coins. Greedy 20, 20, 20 is stuck with 3 and wrongly concludes that no combination works, 20 + 20 + 12 + 5 + 5 = 62 is one short (5 coins), and 20 + 20 + 12 + 12 = 64 overshoots (4 coins).

More Coding Interview Problems questions

Exams that ask this topic