Amazon OA Interview Question: Minimum Bills and Coins for Change

17 Views
No Comments

Q1

Given a sum of money, compute the minimum number of bills and coins that equal that sum.

Assume you only have the following denominations:

  • Bills: 20, 10, 5, 1
  • Coins: 0.25, 0.10, 0.05, 0.01

For example, given 6.35 the solution would be one 5, one 1, one 0.25, one 0.10.

Q2

You will now be given a cash drawer that defines how much of each bill and coin you have to make change with. Now, given a sum of money and a cash drawer, compute the minimum number of bills and coins.

For example, given that you need to give change for 40.05 and you have a cash drawer of one 20, one 10, ten 5s, ten 0.1s, the solution would be one 20, one 10, two 5s, five 0.1s.

Notes before you get started:

  • Solve Q1 before moving on to Q2.
  • The solution will be evaluated on code maintainability. Think about how to organize your code to best solve Q1 and Q2.

This Amazon OA question is a minimum-change problem with two stages. In Q1, the denominations are canonical, so a greedy strategy works: always take as many of the largest bill or coin as possible, then move to the next smaller denomination. In Q2, the cash drawer adds inventory limits, so the algorithm must cap each denomination by what is available while still trying larger values first. A clean implementation usually converts money to cents, reuses the same change-making helper for both parts, and separates denomination handling from drawer availability to keep the code maintainable.

END
 0