Min Coin
Submissions: 8684   Accuracy:


  Difficulty: Medium   Marks: 4

Given a list of coins of distinct denominations and total amount of money. Output the minimum number of coins required to make up that amount. Output -1 if that money cannot be made up using given coins.
You may assume that there are infinite numbers of coins of each type.

The first line contains 'T' denoting the number of testcases. Then follows description of testcases.
Each cases begins with the two space separated integers 'n' and 'amount' denoting the total number of distinct coins and total amount of money respectively.
The second line contains n space-separated integers A1, A2, ..., An denoting the values of coins.

For each testcase, in a new line, print the minimum number of coins required to make up that amount, print -1 if it is impossible to make that amount using given coins.


Input :
3 11
1 2 5
2 7
2 6

Output :


** For More Input/Output Examples Use 'Expected Output' option **

Author: dipjal1996

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.