FastPrepMinimum Cash Pieces with Limited Inventory
Problems/Minimum Cash Pieces with Limited Inventory

Minimum Cash Pieces with Limited Inventory

Amazon logoAmazon● MediumNEW GRADONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report specifies the denominations, minimum-piece objective, limited-inventory follow-up, and exact-change failure case, but not a callable interface or bounds. The judged core task matches the report at about 97%.

A cash drawer contains bills and coins in the fixed denomination order [2000, 1000, 500, 100, 25, 10, 5, 1], measured in cents. The value inventory[i] is the number of available pieces of denomination i.

Given amountCents, return the minimum number of available bills and coins needed to make that amount exactly. Each piece may be used at most once.

Return -1 when the drawer cannot make exact change. The amount is already represented in cents, so no floating-point arithmetic is needed.

Function

minimumCashPieces(amountCents: int, inventory: int[]) → int

Examples

Example 1

amountCents = 635inventory = [1,1,1,1,1,1,1,100]return = 4

Use one 500-cent bill, one 100-cent bill, one quarter, and one dime for 4 pieces.

Example 2

amountCents = 30inventory = [0,0,0,0,1,3,0,0]return = 3

Using the quarter would leave 5 cents, which cannot be formed. Three dimes make exact change with 3 pieces.

Example 3

amountCents = 3inventory = [0,0,0,0,0,0,0,2]return = -1

The drawer contains only two pennies, so it cannot make 3 cents exactly.

Constraints

  • inventory.length == 8.
  • 0 <= amountCents <= 10^5.
  • 0 <= inventory[i] <= 10^4.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
public int minimumCashPieces(int amountCents, int[] inventory) {
  // Write your code here
}
Checking account…