Free round · medium · about 20 min

Vending Machine Coin Change

Solve it here, in your browser. No account needed.

An automated vending machine dispenses change using a given set of coin denominations coins. You have an unlimited supply of each coin denomination listed.

Given an array of positive integers coins and a non-negative integer amount representing the total change required, return the fewest number of coins needed to make up that exact amount.

If that amount cannot be made up by any combination of the coins, return -1.

If amount is 0, 0 coins are needed (0).

Visible tests

Write your solution, then press Run. Your code runs in your browser; nothing is sent to us.

The full round adds

  • Hidden edge-case and speed tests
  • Mocky, the AI assistant, with a two-prompt budget
  • A score, a debrief and your progress over time
  • Six more languages, from Java to Go