Wrong output exchanging coins


what i am doing wrong?

@shivansh.sm1,
Frankly everything,

  • You are not initialising the dp array(here for eg, with all zeros)
  • Also I don’t think you have understood the problem, correctly, you can do n/2 even if n%2!=0, you just have to make maximum weight.
  • Why do you have a parameter called coins, you don’t even change it in recursive calls. Also for any n, you have to compare the sum of weight returned by recursive calls. Not with “coins”
  • Also, as you can see constraints are quit large, dp array of size 100 or even 1e6 would not be sufficient, just STL map to memoize here.