Problem · Dynamic Programming
MediumOmnissaONSITE INTERVIEW

Problem 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) → int

Examples

Example 1

coins = [1,2,5]amount = 11return = 3

11 = 5 + 5 + 1, so the minimum number of coins is 3.

Example 2

coins = [2]amount = 3return = -1

No combination of coin 2 can make amount 3.

More Omnissa problems

drafts saved locally
public int coinChange(int[] coins, int amount) {
  // write your code here
}
coins[1,2,5]
amount11
expected3
checking account