Data Structures & AlgorithmsHardICPC regional · DP vs greedy round

Problem: Coins of values {1, 3, 4} are available, unlimited copies each. To make amount 6, the greedy algorithm always takes the largest coin not exceeding the remaining amount. How many coins does greedy use, and how many does an optimal solution use?

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

Correct answer: A. greedy 3, optimal 2

Greedy takes 4, then 1, then 1 (3 coins), while 3 + 3 uses only 2 coins. Greedy is not optimal for arbitrary coin systems.

More Coding Interview Problems questions

Exams that ask this topic