Skip to content

Commit

Permalink
Update Day08/Number of Coins.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
muditmahajan21 committed May 21, 2022
1 parent ed984c4 commit a6eff56
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Day08/Number of Coins.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
int minCoins(int coins[], int M, int V)
{
// Your code goes here
vector<int> dp(V + 1, INT_MAX);
dp[0] = 0;
for(int i = 1; i <= V; i++) {
for(int j = 0; j < M; j++) {
if(coins[j] <= i) {
int res = dp[i - coins[j]];
if(res != INT_MAX and res + 1 < dp[i]) {
dp[i] = res + 1;
}
}
}
}

return dp[V] == INT_MAX ? -1 : dp[V];
}

0 comments on commit a6eff56

Please sign in to comment.