DP- Coin Change, Bottom Up

int coinchange_bottom(int n, int t, int coins[]){

int dp[100]={0};

for(int i=1; i<=n; i++){

	int ans=INT_MAX;

	for(int j=0; j<t; j++){
		
		if(n-coins[j]>=0){

			ans=min(dp[n-coins[j]]+1,ans);

			dp[i]=ans;
		}

	}

}

return dp[n];

}

I am getting answer as 2 for 15 and 9 whereas the correct answer for both should be 3. I cannot find the mistake in the code please help.

coins[]={1,7,10};
t=3;

@rachitbansal2500 share your full code using online cb ide link

https://ide.codingblocks.com/s/260365 @vatsal38

@rachitbansal2500 corrected


dont forget to hit like and mark resolved if cleared :smiley:

1 Like

Thank you so so much!