Fewest Bills and Coins
Updated
Problem statement
You need to pay out amount cents using as few bills and coins as possible. There is no limit on how often each of these US values may be used:
- Bills: $100, $50, $20, $10, $5 and $1, which are
10000,5000,2000,1000,500and100cents. - Coins: a quarter, a dime, a nickel and a penny, which are
25,10,5and1cents.
Give the pieces back as pairs [value, count] in a list. Here value is a bill or coin value in cents, and count is how many of it you use. Include only the values you actually use, and list them from the largest value to the smallest. With these values, exactly one breakdown reaches the smallest piece count, so each amount has a single correct result.
When amount is 0, no pairs are returned (an empty list).
Function
makeChange(amount: int) → int[][]Examples
Example 1
amount = 12500return = [[10000,1],[2000,1],[500,1]]12500 cents is $125. One $100 bill leaves $25, one $20 bill leaves $5, and one $5 bill finishes it. That is 3 pieces, and no smaller set of pieces adds up to $125.
Example 2
amount = 4199return = [[2000,2],[100,1],[25,3],[10,2],[1,4]]4199 cents is $41.99. Take two $20 bills (4000), one $1 bill (4100), three quarters (4175), two dimes (4195), and four pennies (4199). That is 12 pieces. Values that are not used, such as the $5 bill and the nickel, are left out.
Example 3
amount = 0return = []Nothing has to be paid, so no pairs are returned.
Constraints
0 <= amount <= 10^9
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- Maximum 69 NumberHSBC · ONSITE INTERVIEW
- Maximize the Chance of Selecting the Best CandidateGoogle · ONSITE INTERVIEW
- Spend a Budget Across Five Price TiersExpedia · ONSITE INTERVIEW
- Integer BreakAmazon · ONSITE INTERVIEW
- Maximum Bananas Delivered by a CamelStackAdapt · ONSITE INTERVIEW
- UCB1 Multi-Armed Bandit TraceWayfair · ONSITE INTERVIEW
- Reach a Target by Adding CoordinatesJP Morgan Chase · ONSITE INTERVIEW
- Server InvestmentRippling · OA
- Maximum Three-Server Difficulty ScoreVisa · OA
- Particle Moves to TargetCresta · OA