Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

Problem: How many ways can 10 be made using coins {1, 2, 5} where order does not matter (combinations of coin counts)?

  1. A. 10
  2. B. 128
  3. C. 6
  4. D. 2

Correct answer: A. 10

With the coin loop OUTSIDE the amount loop, each combination is counted once: 10 ways (e.g. 5+5, 5+2+2+1, …, ten 1s). Swapping the loops counts ordered sequences (128), using only coins 1 and 2 gives 6, and 2 is the minimum number of coins (5 + 5).

More Coding Interview Problems questions

Exams that ask this topic