Coin Change
Learn this problemProblem statement
A quick note: this problem is backed by a real Omnissa onsite interview report that directly named Coin Change. The report did not include an exact function interface, examples, constraints, or impossible-case return value. The core task match is about 90%.
You are given coin denominations and a target amount. Return the fewest number of coins needed to make exactly that amount.
You may use each coin denomination any number of times. If the amount cannot be made, return -1.
Interview Follow-up
The candidate walked through brute-force, improved, and 1D dynamic-programming approaches. The interviewer expected working, compilable code in a language of the candidate's choice.
Function
coinChange(coins: int[], amount: int) → intExamples
Example 1
coins = [1,2,5]amount = 11return = 311 = 5 + 5 + 1, so the minimum number of coins is 3.
Example 2
coins = [2]amount = 3return = -1No combination of coin 2 can make amount 3.