Sir doubt in this question

Sir can i get the code for this question using bottom up approach?? as i tried using but its giving me wrong answer why??

@tejasddongare hey share the hackerblock link of the question

sir i am not able to find the link but the name of the question is minimum money change

@tejasddongare try to code using this algo if not able to then i will provide you code.

  • Create matrix min_cost[n+1][W+1], where n is number of distinct weighted packets of orange and W is maximum capacity of bag.
  • Initialize 0th row with INF (infinity) and 0th Column with 0.
  • Now fill the matrix
    • if wt[i-1] > j then min cost[i][j] = min cost[i-1][j] ;
    • if wt[i-1] <= j then min cost[i][j] = min(min cost[i-1][j], val[i-1] + min_cost[i][j-wt[i-1]]);
  • If min cost[n][W]==INF then output will be -1 because this means that we cant not make make weight W by using these weights else output will be min cost[n][W].

sir this is the code but this is giving wrong answer why?