Skip to content
C

Minimum Number of Coins

Mediumjavapythonccppjavascript

Given coin denominations and a target amount, find the minimum number of coins needed to make exactly that amount. Each denomination may be used any number of times.

Input Format

The first line contains an integer N, the number of denominations. The second line contains N space-separated positive integers — the coin values. The third line contains an integer amount.

Output Format

Print the minimum number of coins, or -1 if the amount cannot be formed.

Input (stdin)

Output

Run your code to see output here...