Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given a value **V** and array **coins[]** of size **M**, the task is to make the change for **V** cents, given that you have an infinite supply of each of coins{coins_{1}, coins_{2}, ..., coins_{m}} valued coins. Find the minimum number of coins to make the change. If not possible to make change then return -1.

**Example 1:**

Input: V = 30, M = 3, coins[] = {25, 10, 5}Output:2Explanation: Use one 25 cent coin and one 5 cent coin

Input: V = 11, M = 4,coins[] = {9, 6, 5, 1}Output:2Explanation: Use one 6 cent coin and one 5 cent coin

You don't need to read input or print anything. Complete the function

`minCoins`

() 1 ≤

All array elements are distinct

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Number of Coins

...