Skip to content

Commit da6a534

Browse files
authored
Create Minimum number of Coins .cpp
Given an infinite supply of each denomination of Indian currency { 1, 2, 5, 10, 20, 50, 100, 200, 500, 2000 } and a target value N. Find the minimum number of coins and/or notes needed to make the change for Rs N. You must return the list containing the value of coins required. https://practice.geeksforgeeks.org/problems/-minimum-number-of-coins4426/0
1 parent 4c371b9 commit da6a534

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

Minimum number of Coins .cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Initial Template for C++
2+
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
// } Driver Code Ends
7+
// User function Template for C++
8+
9+
class Solution{
10+
public:
11+
vector<int> minPartition(int x)
12+
{
13+
vector<int>st;
14+
int a[]={1,2,5,10,20,50,100,200,500,2000};
15+
int n=10;
16+
17+
sort(a,a+n,greater<int>());
18+
int ans=0;
19+
for(int i=0;i<n;i++){
20+
// int res=x/a[i];
21+
// if(res>0 ){
22+
// ans=ans+res;
23+
// x=x%a[i];
24+
// st.push_back(a[i]);
25+
// }
26+
while (x >= a[i]) {
27+
x -= a[i];
28+
st.push_back(a[i]);
29+
}
30+
31+
}
32+
33+
34+
return st;
35+
}
36+
};
37+
38+
// { Driver Code Starts.
39+
40+
int main(){
41+
int t;
42+
cin>>t;
43+
while(t--){
44+
int N;
45+
cin>>N;
46+
47+
Solution ob;
48+
vector<int> numbers = ob.minPartition(N);
49+
for(auto u: numbers)
50+
cout<<u<<" ";
51+
cout<<"\n";
52+
}
53+
return 0;
54+
} // } Driver Code Ends

0 commit comments

Comments
 (0)