Skip to content
CampusEduX

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.

Related Problems

  • Activity Selection
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Fractional Knapsack
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Minimum Platforms
    Medium · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...