Data Structures & AlgorithmsHardAccenture · Infosys OA

Problem: Which of these coin systems is a classic counterexample where the greedy 'always take the largest coin' algorithm fails to find the minimum number of coins?

  1. A. No coin system can break greedy
  2. B. Coins {1, 5, 10, 25} (standard currency), any amount
  3. C. Coins {1, 3, 4}, amount 6: greedy gives 4+1+1 (3 coins) but the optimum is 3+3 (2 coins)
  4. D. Coins {1, 2, 5}, any amount

Correct answer: C. Coins {1, 3, 4}, amount 6: greedy gives 4+1+1 (3 coins) but the optimum is 3+3 (2 coins)

With coins {1,3,4}, greedy picks the largest coin not exceeding the remainder first: for 6 that's 4, then 1, then 1 (3 coins), but 3+3 needs only 2; this shows greedy is only safe for canonical coin systems, and DP is needed in general.

More Coding Interview Problems questions

Exams that ask this topic