Minimum number of coins needed

what is the problem in my code please tell me what am i doing wrong in this question…
QUESTION LINK:: https://practice.geeksforgeeks.org/problems/number-of-coins/0
CODE LINK: https://ide.codingblocks.com/s/102534

Hello @sunny.kumar2016 ,

The approach you are using is too complex and inappropriate.

You have no need to use 2D matrix, rather use a 1D matrix mc[v+1].
This matrix will store the minimum number of coins required for i cents.

  1. Initialize mc[0]=0, as no coin is needed for 0 cents.
  2. Initialize all mc values as INT_MAX.
  3. Compute minimum coins required for all values in mc from 1 to v.
    for (int i=1; i<=v; i++) {
    for (int j=0; j<m; j++){
    // check for only those coins having value less than i as there is no sense of taking bigger values.
    if(i>= a[j]){
    int res = table[i-a[j]];
    if (res != INT_MAX && res + 1 < mc[i])
    mc[i] = res + 1;
    }
    }
    }
  4. mc[v] is the required count. //check if there is no coin.

For better understanding of the concept refer this.

Hope, this would help.
Give a like, if you are satisfied.