{"id":"9e5cb709-c4a6-4162-b3cb-bf1926962571","name":"Coin Change - Combinations - 1","description":"1. You are given a number n, representing the count of coins.\r\n2. You are given n numbers, representing the denominations of n coins.\r\n3. You are given a number \"amt\".\r\n4. You are required to calculate and print the combinations of the n coins (non-duplicate) using \r\n which the amount \"amt\" can be paid.\r\n\r\nNote -> Use the code snippet and follow the algorithm discussed in question video. The judge can't \r\n force you but the intention is to teach a concept. Play in spirit of the question.","inputFormat":"A number n\r\nn1\r\nn2\r\n.. n number of elements\r\nA number amt","outputFormat":"Check the sample output and question video","constraints":"1 &lt;= n &lt;= 30\r\n0 &lt;= n1, n2, .. n elements &lt;= 20\r\n0 &lt;= amt &lt;= 50","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\n void coinChange(int i, vector<int>coins, int amtsf, int tamt, string asf)\n {\n if(i==coins.size())\n {\n if(amtsf==tamt)\n {\n cout<<asf<<\".\"<<endl;\n }\n return;\n }\n coinChange(i+1,coins,amtsf+coins[i],tamt,asf+to_string(coins[i])+\"-\");\n coinChange(i+1,coins,amtsf+0,tamt,asf);\n\n }\n int main()\n {\n int n;\n cin>>n;\n vector<int>coins(n);\n for(int i=0;i<n;i++)\n {\n cin>>coins[i];\n }\n int amt;\n cin>>amt;\n coinChange(0, coins, 0, amt, \"\");\n }"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void coinChange(int i, int[] coins, int amtsf, int tamt, String asf){\r\n // write your code here\r\n }\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n int n = Integer.parseInt(br.readLine());\r\n int[] coins = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n coins[i] = Integer.parseInt(br.readLine());\r\n }\r\n int amt = Integer.parseInt(br.readLine());\r\n \r\n coinChange(0, coins, 0, amt, \"\");\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"5\r\n2\r\n3\r\n5\r\n6\r\n7\r\n12","sampleOutput":"2-3-7-.\r\n5-7-.","questionVideo":"https://www.youtube.com/embed/ZiwJdiSGXB4?end=198","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"073d6b1e-cad6-490a-8105-bb94933f140c","name":"Coin Change - Combinations - 1","slug":"coin-change-combinations-1","type":1}],"next":{"id":"85cb64c1-c744-4edb-b179-c8713a103db3","name":"Coin Change - Combinations - 1 MCQ","type":0,"slug":"coin-change-combinations-1-mcq"},"prev":{"id":"d7a17f8b-abd0-4dfc-9c46-06edff05e6d3","name":"Nqueens Permutations - 2d As 1d - Queen Chooses MCQ","type":0,"slug":"nqueens-permutations-2d-as-1d-queen-chooses-mcq"}}}

Coin Change - Combinations - 1

1. You are given a number n, representing the count of coins. 2. You are given n numbers, representing the denominations of n coins. 3. You are given a number "amt". 4. You are required to calculate and print the combinations of the n coins (non-duplicate) using which the amount "amt" can be paid. Note -> Use the code snippet and follow the algorithm discussed in question video. The judge can't force you but the intention is to teach a concept. Play in spirit of the question.

{"id":"9e5cb709-c4a6-4162-b3cb-bf1926962571","name":"Coin Change - Combinations - 1","description":"1. You are given a number n, representing the count of coins.\r\n2. You are given n numbers, representing the denominations of n coins.\r\n3. You are given a number \"amt\".\r\n4. You are required to calculate and print the combinations of the n coins (non-duplicate) using \r\n which the amount \"amt\" can be paid.\r\n\r\nNote -> Use the code snippet and follow the algorithm discussed in question video. The judge can't \r\n force you but the intention is to teach a concept. Play in spirit of the question.","inputFormat":"A number n\r\nn1\r\nn2\r\n.. n number of elements\r\nA number amt","outputFormat":"Check the sample output and question video","constraints":"1 &lt;= n &lt;= 30\r\n0 &lt;= n1, n2, .. n elements &lt;= 20\r\n0 &lt;= amt &lt;= 50","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\n void coinChange(int i, vector<int>coins, int amtsf, int tamt, string asf)\n {\n if(i==coins.size())\n {\n if(amtsf==tamt)\n {\n cout<<asf<<\".\"<<endl;\n }\n return;\n }\n coinChange(i+1,coins,amtsf+coins[i],tamt,asf+to_string(coins[i])+\"-\");\n coinChange(i+1,coins,amtsf+0,tamt,asf);\n\n }\n int main()\n {\n int n;\n cin>>n;\n vector<int>coins(n);\n for(int i=0;i<n;i++)\n {\n cin>>coins[i];\n }\n int amt;\n cin>>amt;\n coinChange(0, coins, 0, amt, \"\");\n }"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void coinChange(int i, int[] coins, int amtsf, int tamt, String asf){\r\n // write your code here\r\n }\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n int n = Integer.parseInt(br.readLine());\r\n int[] coins = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n coins[i] = Integer.parseInt(br.readLine());\r\n }\r\n int amt = Integer.parseInt(br.readLine());\r\n \r\n coinChange(0, coins, 0, amt, \"\");\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"5\r\n2\r\n3\r\n5\r\n6\r\n7\r\n12","sampleOutput":"2-3-7-.\r\n5-7-.","questionVideo":"https://www.youtube.com/embed/ZiwJdiSGXB4?end=198","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"073d6b1e-cad6-490a-8105-bb94933f140c","name":"Coin Change - Combinations - 1","slug":"coin-change-combinations-1","type":1}],"next":{"id":"85cb64c1-c744-4edb-b179-c8713a103db3","name":"Coin Change - Combinations - 1 MCQ","type":0,"slug":"coin-change-combinations-1-mcq"},"prev":{"id":"d7a17f8b-abd0-4dfc-9c46-06edff05e6d3","name":"Nqueens Permutations - 2d As 1d - Queen Chooses MCQ","type":0,"slug":"nqueens-permutations-2d-as-1d-queen-chooses-mcq"}}}
plane

Editor


Loading...

Coin Change - Combinations - 1

medium

1. You are given a number n, representing the count of coins. 2. You are given n numbers, representing the denominations of n coins. 3. You are given a number "amt". 4. You are required to calculate and print the combinations of the n coins (non-duplicate) using which the amount "amt" can be paid. Note -> Use the code snippet and follow the algorithm discussed in question video. The judge can't force you but the intention is to teach a concept. Play in spirit of the question.

Constraints

1 <= n <= 30 0 <= n1, n2, .. n elements <= 20 0 <= amt <= 50

Format

Input

A number n n1 n2 .. n number of elements A number amt

Output

Check the sample output and question video

Example

Sample Input

5 2 3 5 6 7 12

Sample Output

2-3-7-. 5-7-.

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode