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

Minimum Cash Pieces with Limited Inventory

Amazon logoAmazon● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon new grad onsite interview. The report gives the denominations, the goal of using the fewest pieces, the follow-up with a limited supply, and what happens when exact change is impossible. It does not give a function signature or limits. Our version is about 97% the same as the reported question.

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 Onsite Interview questions

  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dungeon GameONSITE INTERVIEW · Seen Nov 2026
  • Integer BreakONSITE INTERVIEW · Seen Nov 2026
  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Count Subsets With a Target SumSafe Security · ONSITE INTERVIEW
  • 0/1 Knapsack with Weight and Volume LimitsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Maximum Subarray Sum with One DeletionOracle · ONSITE INTERVIEWOracle interview questions
  • Best Time to Buy and Sell Stock IIKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Coin ChangeMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Maximum SubarrayUpstart · ONSITE INTERVIEWUpstart interview questions
  • Smallest Sufficient TeamExpedia · ONSITE INTERVIEWExpedia interview questions
  • Maximum Product SubarrayHartford Financial Services · ONSITE INTERVIEWHartford Financial Services interview questions
  • Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions
  • Maximum Value from Circular HousesDigitalOcean · ONSITE INTERVIEWDigitalOcean interview questions

Interview reports that mention this question

  • Amazon New Grad SDE Onsite Interview Questions: 17 Experiences

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences
  • Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
See Amazon hiring insights
Saved
class Solution {
    public int minimumCashPieces(int amountCents, int[] inventory) {
      // Write your code here
    }
}
Checking account…