Not sure what to study next?

Get a personalised quant interview roadmap built around your upcoming interviews, strengths and weaknesses.

Takes a few minutes. Start with your target role and firms.

← Programming questions
Medium / PYTHON

Minimum Coins with Unlimited Reuse

dynamic_programming · arrays 28 minute study target

Not completed

Challenge

Find the smallest number of coins whose values sum exactly to amount. Each denomination may be used any number of times. Return -1 if the amount is impossible. Repeated denominations in coins are redundant, not separate supplies.

Input and output contract

0 ≤ amount ≤ 10,000; at most 50 input denominations, each an integer from 1 to 10,000. Empty denominations are allowed. Amount zero always requires zero coins. d is the number of distinct denominations.

All tests follow this contract. You do not need to validate malformed input. Return the requested result from coin_change; printed output is not your answer. Standard-library tools are allowed. Implement your solution in Python 3.12.

Target complexity: O(amount × d + d log(d + 1)) time; O(amount + d) auxiliary space

Return values are checked by type. Use the exact function name. Print output is not your answer. Tests have time and memory limits.

Public examples

Example 1

Arguments

[[1, 3, 4], 6]

Expected return

2
Example 2

Arguments

[[2], 3]

Expected return

-1
Example 3

Arguments

[[], 0]

Expected return

0
Hint

Let best[x] be the minimum coins for total x. Consider the denomination of the last coin.

The worked solution unlocks after completion, or with Premium access.

coin_change.pyPython 3.12

Drafts are saved to your account, not to shared browser storage.

Sign in to submit code and save progress.

Results

Your results will appear here.

Hidden tests reveal only their pass/fail status, never their inputs or expected outputs. Runtime is observed wall time—not an inferred complexity class.

Join our Newsletter and Receive the Latest Updates!

Main Links

Trade Courses Assessments Interview Prep Contact Us

Social Media

Facebook Instagram YouTube

Legal

Terms and Conditions Privacy Policy Privacy settings

Talent Acquisition

Looking to hire exceptional quant talent?
See how we can help.

© 2026 EverythingQuant. All Rights Reserved.