Minimum coins problem

hello,can anybody help me with minimum coin problem.I just implemented for sake of learning.There is no problem link.Here is my solution can you please see and guide newbie like me?Is my approach correct or Is it wrong.i am asking this type of question because i found no problem exact to what i wanted to implement.
I request you to please give some problem link very similar to my solution(concept wise) and review my code and give your precious suggestion.My solution link

1 Like

Your code will work only when the array coins will be sorted otherwise, it may not give the correct answer. Check output when:

coins[]= {3,1,5}
 and sum=3

When the coins array is sorted, you’ll always get minimum value for increasing values of j, but when it is unsorted, ex, in the case above, we get minimum number of coins for n=3 when j=0, but your solution will give answer as 3 as you are not finding the minimum. So, do this little modification.

Hope it clears… :slight_smile:

2 Likes

dp[i]=max; and max==1000(why 1000) //can you explain why you did this… rest all is clear :slight_smile: :slight_smile:

I just selected some maximum value lets say 1000. For finding minimum you need to assume that the possible answer is some value max, you can take any other value as the maximum.

1 Like

ok ok…just like max=INT_MAX

Yeah… the very same!!

1 Like