Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

Coins have values 1, 3, 9, 27, 81, ... (powers of three, unlimited supply). What is the minimum number of coins needed to pay exactly 41?

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

Correct answer: D. 5

41 written in base 3 is 1112, and the minimum number of powers of three summing to 41 equals its digit sum, 1 + 1 + 1 + 2 = 5. Taking the largest coin first is optimal for these coin values.

More Coding Interview Problems questions

Exams that ask this topic