id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,464 | <p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p>
<p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p>
<p> </p>
<p><strong class="ex... | 3 | {
"code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n=arr.size();\n priority_queue<pair<int,int>>pq;\n map<int,int>mp;\n for(int i=0;i<arr.size();i++)\n {\n mp[arr[i]]++;\n }\n for(auto x:mp)\n {\n pq.push({x.... |
1,464 | <p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p>
<p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p>
<p> </p>
<p><strong class="ex... | 3 | {
"code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n int n=arr.size();\n unordered_map<int,int>mp;\n for(int i=0;i<arr.size();i++){\n mp[arr[i]]++;\n }\n vector<pair<int,int>>v;\n for(auto it:mp){\n v.push_back({it.second,it.fir... |
1,464 | <p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p>
<p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p>
<p> </p>
<p><strong class="ex... | 3 | {
"code": "class Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n unordered_map<long,long>fre;\n long n=arr.size();\n\n for(auto& ele:arr){\n fre[ele]++;\n }\n\n priority_queue<long>p;\n \n for(auto& ele:fre){\n p.push(ele.second);\n ... |
1,464 | <p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p>
<p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p>
<p> </p>
<p><strong class="ex... | 3 | {
"code": "#include <unordered_map>\n#include <queue>\n\nclass Solution {\npublic:\n int minSetSize(vector<int>& arr) {\n std::unordered_map<int, size_t> counter;\n for (auto el: arr)\n counter[el]++;\n \n std::priority_queue<size_t> el_counts;\n for (auto [el, counter... |
1,464 | <p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p>
<p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p>
<p> </p>
<p><strong class="ex... | 3 | {
"code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\n\nauto disableSync = [](void) noexcept -> int\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\nclass Solution final\n{\npublic:\n int minSetSize(const std::vector<int>& nums) con... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 0 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n int dp[amount+1];\n for(int i = 1; i <= amount; i++)dp[i] = 1e9;\n dp[0] = 0;\n for(int i = 1; i <= amount; i++){\n for(int x : coins){\n if(i >= x)dp[i] = min(dp[i], 1 + ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 0 | {
"code": "class Solution\n{\npublic:\n int coinChange(vector<int> &coins, int amount)\n {\n int dp[amount + 1];\n dp[0] = 0;\n for (int i = 1; i <= amount; ++i)\n {\n dp[i] = amount + 1;\n for (int x: coins)\n {\n if (i - x < 0) contin... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 0 | {
"code": "#define ll long long\nvector<ll>coins_now;\nll n;\nll dp[100005];\n\nll func(ll koto)\n{\n //cout<<\"koto: \"<<koto<<endl;\n if(koto==n){return 0;}\n else if(koto>n){return 1e9;}\n if(dp[koto]!=-1)\n {\n return dp[koto];\n }\n ll koita=1e18;\n for(int i=0;i<coins_now.size();i... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 0 | {
"code": "#include <algorithm>\n#include <limits>\n#include <functional>\n#include <unordered_map>\n\nclass Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n const int MAX = 10001;\n int dp[MAX];\n std::fill(dp, dp + MAX, MAX);\n dp[0] = 0;\n \n for... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 0 | {
"code": "class Solution {\npublic:\n int dp[10001][12];\n int func(vector<int>& coins, int amount,int i){\n int n = coins.size();\n if(amount == 0){\n return 0;\n }\n\n int ans = INT_MAX;\n\n if(i>=n || amount<0){\n return INT_MAX;\n }\n\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 0 | {
"code": "class Solution {\npublic:\n long long int a[(unsigned long)1e4+1][13];\n long long int coinChange(vector<int>& coins, int amount) {\n for(int i=0;i<1e4+1;i++)\n {\n for(int j=0;j<13;j++)\n {\n a[i][j]=-1;\n }\n }\n for(in... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 0 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int> &coins, int amount) {\n if (!amount)\n return 0;\n\n vector<short> lefts_coin_cnt(amount + 1, -1);\n lefts_coin_cnt[amount] = 0;\n\n for (int coin_cnt = 1, new_left_cnt = 1; coin_cnt <= amount && new_left_cnt;\n ++coin_cnt) {\... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 0 | {
"code": "short min(short a, short b) {\n return a < b ? a : b;\n}\n\nclass Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n vector<short> dp(amount + 1, SHRT_MAX);\n dp[0] = 0;\n // Time complexity O(N * M)\n // N -> amount of coins\n // M -> designat... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 0 | {
"code": "class Solution {\npublic:\n vector<int> arr;\n int n ;\n int target;\n int t[13][10001];\n int fun(int idx,long currSum){\n if (idx == n) return INT_MAX-1;\n if (currSum > target) return INT_MAX-1;\n if (currSum == target) return 0;\n if (t[idx][currSum] != -1) re... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 0 | {
"code": "class Solution {\npublic:\nint n;\nint coin[12];\nint dp[12][10001];\n int rec(int i, int left){\n if(left<0) return 1e9;\n if(i==n){\n if(left==0) return 0;\n else return 1e9;\n }\n\n if(dp[i][left]!=-1) return dp[i][left];\n int ans=1e9;\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 0 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n int m=amount+1;\n vector<int>dp(m,m);\n dp[0]=0;\n for(int i=1;i<m;i++){\n for(int j=0;j<coins.size();j++){\n if(coins[j]<=i){\n dp[i]=min(dp[i],dp[i-co... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 0 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n vector<int> dp(amount + 1, amount + 1);\n dp[0] = 0;\n \n for (int i = 1; i <= amount; i++) {\n for (int coin : coins) {\n if (coin <= i) {\n dp[i] = mi... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 1 | {
"code": "class Solution {\npublic:\n int solveusingTab(vector<int>& coins, int amount) {\n sort(coins.rbegin(), coins.rend());\n\n // Create a dp array of size amount + 1, initialized to INT_MAX\n vector<int> dp(amount + 1, INT_MAX);\n dp[0] = 0; // No coins are needed to make the am... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 1 | {
"code": "class Solution {\npublic:\n int solveusingTab(vector<int>& coins, int amount) {\n sort(coins.rbegin(), coins.rend());\n\n // Create a dp array of size amount + 1, initialized to INT_MAX\n vector<int> dp(amount + 1, INT_MAX);\n dp[0] = 0; // No coins are needed to make the am... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 1 | {
"code": "class Solution {\npublic:\n\n\n int findFewestByRecursion(vector<int>& coins, int amount){\n\n /// base case\n if(amount == 0) return 0;\n if( amount < 0) return INT_MAX;\n\n\n int mini = INT_MAX;\n for(int i = 0; i < coins.size(); i++){\n int ans = findFewe... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 1 | {
"code": "class Solution {\npublic:\n int ans = INT_MAX;\n vector < int > memo;\n int ways(int amount, vector < int > &coins)\n {\n if(amount<0) return INT_MAX;\n if(amount==0)\n {\n return 0;\n }\n if(memo[amount]!=-1) return memo[amount];\n int min_c... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 1 | {
"code": "const int N = 15,M = 1e5;\nint mem[N][M];\nint n;\nclass Solution {\npublic:\n int dp(int ind,int amount,vector<int>& coins)\n {\n if(amount==0)\n return 0;\n int &ret = mem[ind][amount];\n if(~ret)return ret;\n ret = 1e9;\n for(int i=0;i<n;i++)\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int> &coins, int amount) {\n /* 1 2 5\n * 11 | 10 9 6 | 5 8 7 4 5 1 | 3 0 (done)\n *\n * amount = x^a + y^b + ...\n */\n if (!amount)\n return 0;\n\n vector<int> lefts{amount};\n bitset<10000> is_left;\n\n for (int coin_... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n long long int dp[100000][13];\n long long int helper(vector<int>& coins, int amount , long long int sum , int index)\n {\n if(index == coins.size() || sum > amount){\n return INT_MAX -1; \n }\n if(sum == amount){\n ret... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n /* cal(amt, ind) = cal(amt, ind-1) | cal(amt-coins[ind], ind); */\n int n = coins.size();\n vector<vector<int>>dp(2, vector<int>(amount+1,amount+1));\n dp[1][0] = 0;\n for(int i = 0; i < n; ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic://now lets solved this using 2d dp tabulation\n int coinChange(vector<int>& coins, int amount) {\n int n=coins.size();\n //lets declare our dp vector of 2d\n vector<vector<int>>dp(2,vector<int>(amount+1,INT_MAX)); //initializing with INT_MAX\n //now ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n queue<pair<int,int>> q;\n vector<int> vis(amount+1,0);\n if(amount == 0){\n return 0;\n }\n q.push({amount,0});\n vis[amount] = 1;\n while(!q.empty()){\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\n\npublic:\n int coinChange(vector<int>& coins, int amount) {\n if(amount == 0){return 0;}\n sort(coins.begin(), coins.end());\n int ind = coins.size()-1;\n int minn = 1e9;\n queue<pair<pair<int,int>,int>> q;\n q.push({{amount,0},ind});\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "// class Solution {\n// public:\n// int coinChange(vector<int>& coins, int amount) {\n// const int optimal = GetOptimal(0, amount, coins);\n// return optimal == INT_MAX ? -1 : optimal;\n// }\n// private:\n// int GetOptimal(const int idx, const int rem_amount, const vector<int>& ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n int n = coins.size();\n vector<long> prev(amount+1, 1e9), curr(amount+1, 1e9); // Initialize DP table with large values\n prev[0]=0; curr[0]=0;\n\n for (int i = 1; i <= amount; i++) {\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n long long int miniCoinR(vector<int> &coins,int idx,int amount){\n if(amount==0){\n return 0;\n }\n if(idx==0){\n return INT_MAX;\n }\n if(coins[idx-1]>amount){\n return miniCoinR(coins,idx-1,amount);\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n int n = coins.size();\n vector<long> prev(amount+1, 1e9), curr(amount+1, 1e9); // Initialize DP table with large values\n prev[0]=0; curr[0]=0;\n\n for (int i = 1; i <= amount; i++) {\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int f(int ind,int target, vector<int>& coins,vector<int> prev,vector<int> curr){\n int n=coins.size();\n \n for (int t = 0; t <= target; t++) {\n if (t % coins[0] == 0) {\n prev[t] = t / coins[0];\n }\n }\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n if (amount == 0) return 0;\n deque<pair<int64_t,int64_t>> dq;\n dq.emplace_back(0LL,0);\n vector<bool> visit(amount+1);\n while (!dq.empty()) {\n auto [cur, step] = dq.front(); dq... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& a, int k) \n {\n if(k==0)\n return 0;\n int n=a.size();\n sort(a.begin(),a.end());\n vector<long long int> dp(10005,INT_MAX);\n dp[0]=0;\n for(int i=0;i<10005;i++)\n {\n for(... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& a, int k) \n {\n if(k==0)\n return 0;\n int n=a.size();\n // sort(a.begin(),a.end());\n vector<long long int> dp(10005,INT_MAX);\n dp[0]=0;\n for(int i=0;i<10005;i++)\n {\n f... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution { \npublic:\n int coinChange(vector<int> &coins, int amount) \n {\n vector <int> prev(10001), now(10001);\n for(int am=0; am<=amount; am++)\n prev[am] = am%coins[0]==0 ? am/coins[0] : 1e9;\n for(int cur=1; cur<coins.size(); cur++)\n {\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\n vector<long> dp;\npublic:\n Solution() {\n dp = vector<long>(10001, -1); \n }\npublic:\n int coinChange(vector<int>& coins, int amount) {\n //init(amount);\n long ans = numCoins(amount, coins);\n return (ans >= INT_MAX) ? -1 : ans;\n }\n\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n if(amount == 0){\n return 0;\n }\n if(coins.size() == 1){\n if(amount % coins[0]){\n return -1;\n }\n else{\n return amount / coin... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n if(amount == 0){\n return 0;\n }\n if(coins.size() == 1){\n if(amount % coins[0]){\n return -1;\n }\n else{\n return amount / coin... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n if(amount == 0){\n return 0;\n }\n if(coins.size() == 1){\n if(amount % coins[0]){\n return -1;\n }\n else{\n return amount / coin... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "// class Solution {\n// public:\n// int coinChange(vector<int>& coins, int amount) {\n// GetOptimal(coins, amount, 0);\n// const int num_coins = dp_[std::make_pair(0, amount)];\n// if (num_coins == INT_MAX) { return -1; }\n// return num_coins;\n// }\n// private:\n// ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\nint t[14][400001];\n int dp(vector<int>& coins, int n, int amount) {\n if(amount==0) return 0;\n if(n<0)\n {\n return 1e9;\n }\n if(t[n][amount]!=-1) return t[n][amount];\n int nottake=0+dp(coins,n-1,amount);\n int take... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n vector<int> dp(amount + 1, INT_MAX);\n vector<bool> visited(amount + 1, false);\n dp[amount] = 0;\n queue<int> q;\n q.push(amount);\n while (!q.empty()) {\n int front = q.f... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n const unsigned tot_coins = coins.size();\n const unsigned max_amount = amount + 1;\n const unsigned arr_dimm = tot_coins * max_amount;\n int* arr = new int[arr_dimm];\n for (unsigned coin = ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "#define INVALID -1\nclass Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n const unsigned tot_coins = coins.size();\n const unsigned max_amount = amount + 1;\n const unsigned arr_dimm = tot_coins * max_amount;\n int* arr = new int[arr_dimm];\n f... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "#include<map>\n\nclass Solution {\npublic:\n int *arr;\n int dimx, dimy;\n int coinChange(vector<int>& coins, int amount) {\n dimx = coins.size();\n dimy = amount;\n arr = new int[dimx * dimy + 1];\n std::cout << dimx * dimy << \"\\n\";\n for (unsigned i = 0; i <... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int *arr;\n int dimx, dimy;\n int coinChange(vector<int>& coins, int amount) {\n dimx = coins.size();\n dimy = amount;\n arr = new int[dimx * dimy + 1];\n for (unsigned i = 0; i < dimx * dimy + 1; i++) {\n arr[i] = -2;\n }\n... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n if(amount==0){\n return 0;\n }\n vector<int> prev(amount+1, 0);\n prev[0] = 0;\n int n = coins.size();\n for(int j = 1;j<=amount;j++){\n if(coins[0]<=j && j%coin... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int f(vector<int>&coins,int ind,int amt,vector<vector<int>>&dp)\n {\n //base case here\n if(ind==0)\n {\n if(amt%coins[ind]==0)\n return amt/coins[ind];\n return 1e9;\n }\n if(... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n // int helper(int ind,int w,vector<int> &coins,vector<vector<int>> &dp){\n // if(w == 0) return dp[ind][w] = 0;\n // if(ind == 0){\n // if(coins[0] == w) return dp[ind][w] = 1;\n // else{\n // if(w % coins[0] == 0) return dp[... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n vector<pair<long long,long long>> queue;\n int coinChange(vector<int>& c, int amount) {\n if(amount==0)\n return 0;\n sort(c.begin(),c.end());\n reverse(c.begin(),c.end());\n \n int left = 0;\n queue.push_back({0,0});\n\... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n int n=coins.size();\n vector<int> dp(amount+1,1e9);\n dp[0]=0;\n for(int i=0;i<n;i++){\n if(coins[i]>amount) continue;\n vector<int> temp(amount+1);\n for(int j=0;j... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n int n = coins.size();\n vector<vector<int>> dp(n, vector<int>(amount + 1, 0));\n for (int j = 0; j < amount + 1; j++) {\n if (j % coins[0] == 0) dp[0][j] = j / coins[0];\n else dp[0]... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n\n int n=coins.size();\n vector<vector<int>> dp(n,vector<int>(amount+1,0));\n\n for (int i = 0; i <= amount; i++) \n {\n if (i % coins[0] == 0)\n dp[0][i] = i / coins[0];\n... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\npublic:\n\n int solveRec(int ind,vector<int> &coins,int amount){\n if(ind == 0){\n if(amount % coins[ind] == 0){\n return (amount/coins[ind]);\n }\n else{\n return 1e9;\n }\n }\n \n in... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "// class Solution {\n// private:\n// int fl(vector<int>& arr, int ind, int t, vector<vector<int>>& dp){\n// if (ind == 0) {\n// if (t % arr[0] == 0){\n// return t / arr[0];\n// }\n// else {\n// return 1e9; \n// }\n// ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 2 | {
"code": "class Solution {\n private:\n int fl(vector<int>& arr, int ind, int t, vector<vector<int>>& dp){\n if (ind == 0) {\n if (t % arr[0] == 0){\n return t / arr[0];\n }\n else {\n return 1e9; \n }\n }\n\n if (dp[ind][t... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> dp; \n \n int solve(int ind, int amount, vector<int> &coins) {\n if (amount == 0)\n return 0; \n \n if (ind == coins.size())\n return 1e9;\n \n if (dp[ind][amount] != -1)\n return dp... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& nums, int k) {\n int n = nums.size();\n sort(nums.rbegin(),nums.rend());\n\n vector<vector<int>> dp(n,vector<int>(k+1,-1));\n\n auto give = [&] (auto&& give,int i,int sum) -> int {\n if(sum<0) return 1e8;\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int f(int idx,int amount,vector<int> &coins,vector<vector<int>> &dp){\n if(amount == 0) return 0;\n if(idx == 0){\n if(amount % coins[idx] == 0) return amount/coins[idx];\n return 1e9;\n }\n if(dp[idx][amount] != -1) return ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int inf = 1e4 + 5;\n int res(int x, int amount, vector<int>& coins, vector<vector<int>>& dp){\n // base case\n if(x == 0){\n if(amount%coins[x] == 0){\n return amount/coins[x];\n }\n else{\n return inf;\n }\n }\n // cache check\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n int n = (int) coins.size();\n vector<vector<int>> dp(n, vector<int> (amount + 1, -1));\n function<int(int, int)> f = [&] (int i, int amount) {\n if (amount < 0) return int(1e6);\n if... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n int n = (int) coins.size();\n vector<vector<int>> dp(n, vector<int> (amount + 1, -1));\n function<int(int, int)> f = [&] (int i, int amount) {\n if (amount < 0) return int(1e9);\n if... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n int n=coins.size();\n vector<vector<int>>t(n+1,vector<int>(amount+1));\n // t[0][0];\n for(int i=1;i<=n;i++)t[i][0]=0;\n for(int j=0;j<=amount;j++)t[0][j]=INT_MAX-1;\n \n for(i... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int fun(int ind, int rem, vector<int>& coins, vector<vector<int>>& mem){\n\n if(ind == 0){\n return rem == 0 ? 0 : INT_MAX-1;\n }\n\n if(mem[ind][rem] != -1)\n return mem[ind][rem];\n\n if(rem >= coins[ind-1]){\n re... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n\n int findLowestCoins(vector<int>& coins, int index, int amount,\n vector<vector<int>>& dp) {\n if (index >= coins.size() || amount <= 0) {\n if (amount == 0) {\n return 0;\n }\n return 1e9;\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int fun(vector<int> &v,int ind,int n,int k,vector<vector<int>> &dp)\n {\n if(ind==n)\n {\n if(k==0) return 0;\n else return 1e9;\n }\n\n if(dp[ind][k]!=-1) return dp[ind][k];\n\n // notTake\n int no... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>>dp;\n int chk(int st,int en, vector<int>&coins, int a) {\n if(a==0)\n return 0;\n if(st>=en)\n return INT_MAX;\n if(dp[st][a]!=-1)\n return dp[st][a];\n if(a<coins[st])\n return dp[s... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n\n int solve(int i,int n,vector<int> &coins,int a, vector<vector<int>> &dp){\n\n\n if(i == n){\n if(a == 0) return 0;\n return 1e9;\n }\n\n if(dp[i][a] != -1) return dp[i][a];\n\n int take = 1e9;\n\n if(coins[i] <= a){\... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> memo;\n int getChanges(vector<int> &nums, int target, int idx) {\n if (target == 0) {\n return 0;\n }\n if (memo[idx][target] != -1) {\n return memo[idx][target];\n }\n if (idx >= nums.size() || t... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n int sz = size(coins);\n vector<vector<int>> dp(sz + 1, vector<int>(amount + 1, INT_MAX));\n function<int(int, int)> minCoins = [&](int i, int amount) {\n if(amount == 0)\n return... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "/*\ncoins -> [1 to 2^31]\namount -> [0 to 10000] \n [2,5] amount = 13\n [5] amount => 8 len 5 \n [1,2,5] => 11\n [1,2,5] => 6\n 1. if amount == currSumOfCoins I have reached return len;\n 2. if idx > coins.size() return INT_MAX; \n\n prune sort the coins then if you know the currentLeftAmount<coins[idx]... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int rec (long long i, vector<int>& coins, long long n, long long amount, long long curramt, vector<vector<int>>& dp){\n if(i>=n) return 1e9;\n if (curramt == amount) return 0;\n if(dp[i][curramt]!=-1) return dp[i][curramt];\n long long take = 1e9;\... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n\n int solve(vector<int>& coins,int amount,int idx,vector<vector<int>>& dp){\n\n if(idx==0){\n\n if(amount % coins[0]==0){\n\n return amount / coins[0];\n }\n\n else return INT_MAX;\n\n }\n\n if(dp[idx][amoun... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\n // //int dp[13][10001];\n // int help(int i, vector<int>& coins, int amount) {\n // if(i==coins.size()-1) {\n // if(amount%coins[i]==0) return amount/coins[i];\n // return 1e9;\n // }\n\n // if(dp[i][amount] != -1) return dp[i][amount];\n\... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int s(int i, int amt, vector<int>&coins,vector<vector<int>> &dp){\n if(amt<0) return 1e9;\n if(amt==0) return 0;\n if(i>=coins.size()) return 1e9;\n if(dp[i][amt]!=-1) return dp[i][amt];\n \n int take = 1e9;\n int notTake = s(i+... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n\nint solve(vector<int>& coins,int i,int amount,vector<vector<int>>&dp){\n\n\nif(amount==0) return 0;\nif(i==coins.size() || amount<0) return 1e9;\nif(dp[i][amount]!=-1) return dp[i][amount];\n\nint ans= min(solve(coins,i+1,amount-coins[i],dp)+1,min(solve(coins,i,amount-coins[i],... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int memo(vector<int> &coins, int amount, int i, vector<vector<int>> &dp) {\n if(amount==0) return 0;\n\n if(i==coins.size()-1) {\n if(amount%coins[i]==0) return amount/coins[i];\n return 1e9;\n }\n\n if(dp[i][amount]!=-1) retu... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int minCoins(vector<int>& coins, int amount, int idx, vector<vector<int>>& dp)\n {\n if(idx == 0)\n {\n if(amount % coins[idx] == 0)\n return amount / coins[idx]; \n return 1e9; \n }\n if(dp[idx][amount] != -... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n//9,6,5,1 greedy: 9,1,1 dp:6,5\n//greedy fails as no unifromity or consistent difference\n int rec(vector<int> &coins, int amount, int i, int n, vector<vector<int>> &dp) {\n if(amount==0) return 0;\n if(amount<0) return INT_MAX;\n if(i==n-1) {\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int f(int ind, int amt, vector<int>& coins) {\n\n if (amt == 0)\n return 0;\n\n if (ind < 0)\n return INT_MAX - 1;\n\n // if (amt % coins[ind] == 0)\n // return amt / coins[ind];\n int ans = INT_MAX - 1;\n if... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int sol(int i,long s,int amount,vector<int>&coins,vector<vector<int>>&v)\n {\n int n = coins.size();\n if(v[i][s]!=-1) return v[i][s];\n if(i==n-1)\n {\n if((amount-s)%coins[i]==0)\n {\n return (amount-s)/coi... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n\n int bfs(vector<int> &coins, int amount)\n {\n queue<pair<int,int>> q;\n\n vector<bool> isVisited(amount+1,false);\n\n for(int i=0;i<coins.size();i++)\n {\n if(coins[i]<=amount)\n {\n q.push({coins[i],1});\n... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int solve(int ind, int amt, vector<int>& cns, vector<vector<int>>& dp) {\n if(amt==0){\n return 0;\n }\n if(ind>=cns.size()){\n return 1e9;\n }\n if(dp[ind][amt]!=-1){\n return dp[ind][amt];\n }\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;\n pq.push({0,amount});\n unordered_set<int>st;\n st.insert(amount);\n while(!pq.empty()){\n int coin=... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\n\npublic:\n\n int coinChange(vector<int>& coins, int amount) {\n\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;\n\n pq.push({0,amount});\n\n unordered_set<int>st;\n\n st.insert(amount);\n\n while(!pq.empty()){\n\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "unordered_map<int, pair<int, int>> store;\nclass Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n sort(coins.begin(), coins.end(), greater<int>());\n store.clear();\n\n return change(coins, amount, 0);\n }\n int change(vector<int>& coins, int amount, in... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\n\n unordered_map<int, unordered_map<int,int>> resMap;\n unordered_map<int, int> resMap2;\npublic:\n int coinChange(vector<int>& coins, int amount, int end) {\n\n \n if(amount == 0)\n {\n return 0;\n }\n\n if(amount < 0)\n {\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n vector<double>dp;\n int helper(vector<int>& coins,int amount,double total){\n if(amount==total){\n return 0;\n }\n if(total>amount){\n return -1;\n }\n\n if(dp[total]!=-2){\n return dp[total];\n }\n... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n unordered_map<int, int> dp;\n dp[0] = 0;\n for (int i = 1; i < amount + 1; i++) {\n for(int coin : coins) {\n if (dp.find(i-coin) != dp.end()) {\n if (dp.find(... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n unordered_map<int, int> dp;\n dp[0] = 0;\n sort(begin(coins), end(coins));\n for (int i = 1; i < amount + 1; i++) {\n for(int coin : coins) {\n if (i - coin < 0) break;\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n // return dp(coins, amount);\n return bfs(coins, amount);\n }\nprivate:\n int dp(vector<int>& coins, int amount) {\n if (amount == 0) return 0;\n\n vector<int> dp(amount+1, amount+1);\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n if (amount == 0) return 0;\n\n queue<int> q;\n q.push(0);\n unordered_set<int> discovered;\n int level = 1;\n\n while (!q.empty()) {\n int sz = q.size();\n for (... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n unordered_map<int, int> dp;\n dp[0] = 0;\n \n for (const auto& coin : coins){\n for (int x = coin; x <= amount; x++){\n if (dp.find(x) == dp.end()){\n d... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int coinChange(vector<int>& coins, int amount) {\n queue<pair<int,int>>q;\n q.push({amount,0});\n unordered_set<int>s;\n s.insert(amount);\n\n while(!q.empty()){\n auto [sum,num]=q.front();\n q.pop();\n if(su... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int getCoins(vector<int>& coins, int amount,unordered_map<int,int>& mp) {\n if(amount == 0)\n return 0;\n if(mp[amount] != 0)\n return mp[amount];\n else {\n mp[amount] = INT_MAX;\n }\n for(int i = 1;i<= ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n int getCoins(vector<int>& coins, int amount,unordered_map<int,int>& mp) {\n if(amount == 0)\n return 0;\n if(mp[amount] != 0)\n return mp[amount];\n else {\n mp[amount] = INT_MAX;\n }\n for(int i = 1;i<= ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\npublic:\n map<int,int> cache;\n\n int solve(vector<int>& coins, int amount){\n if (amount ==0) return 0;\n if (amount < coins.back()) return -1;\n\n auto it = cache.find(amount);\n if (it != cache.end()) return it->second;\n\n int ans = -1;\n ... |
322 | <p>You are given an integer array <code>coins</code> representing coins of different denominations and an integer <code>amount</code> representing a total amount of money.</p>
<p>Return <em>the fewest number of coins that you need to make up that amount</em>. If that amount of money cannot be made up by any combinatio... | 3 | {
"code": "class Solution {\n map<int, int> store;\npublic:\n int coinChange(vector<int>& coins, int amount) {\n if (amount == 0) return 0;\n\n bool notPossible = true;\n for (auto c : coins) {\n notPossible = notPossible && (c > amount);\n }\n if (notPossible) retu... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.